[concurrency-interest] ConcurrentLinkedQueue unexpected behavior ?

Doug Lea dl at cs.oswego.edu
Tue Apr 10 06:09:52 EDT 2007


Hanson Char wrote:
> Here is the proof:
> 
> Running the following test, occasionally I got both x and y as null:
>     http://svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-test/dl/TwoConcurrentLinkedQueueLoops.java?view=markup
> 
> (In the test, x is referred to as result.r1, and y as result.r2)
> 

This doesn't seem to be testing the property that you stated,
that is:

T1           T2
q1.offer     q2.offer
x=q2.poll    y=q1.poll

Your test starts up a large number of pairs, each using the same
queues. This allows, for example, the sequence involving
added thread T3, that is conceptually a member of
a different pair:

T2: q2.offer
T2: y=q1.poll => null
T3: q1.offer
T3: q2.poll => nonnull
T1: q1.offer
T1: x=q2.poll => null

So, both x and y can be null.

-Doug


More information about the Concurrency-interest mailing list