[concurrency-interest] Ordered puts and takes

Christian Vest Hansen karmazilla at gmail.com
Tue May 12 03:50:58 EDT 2009


On Mon, May 11, 2009 at 6:25 PM, Jim Andreou <jim.andreou at gmail.com> wrote:
> I don't see a guarantee that the consumer will observe the program
> order of the producer. The two puts can be reordered if this
> reordering can't be observed in the producer thread, so the consumer
> may see the "wrong" order.

Correct me if I'm wrong, but...

LBQ.put has visibility semantics and reordering is therefor not
allowed, no? Just like volatile and synchronized cannot be reordered.

>
> Also, think that the producer could be preempted before putting to the
> second queue.
>
> I think that if you reordered the consumer like this:
>
> Object seen2 = queueB.take();
> Object seen1 = queueA.remove();
>
> Then you would have the intented ordering. If you see the second
> object, then the put on the queueB happened-before, and the put on
> queueA happened-before that because it was earlier in program order.
>
>>
>> My intuitive answer is yes but the actual answer might be that this is merely likely, not guaranteed.
>>
>> Thanks...
>> Alex
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.


More information about the Concurrency-interest mailing list