[concurrency-interest] concurrency puzzle
Jeremy Manson
jmanson at cs.umd.edu
Sun Sep 10 21:48:21 EDT 2006
yangjs wrote:
> >
>> Some confusion seems to have arisen.
>>
>>> public void foo(){
>>> x = 20;
>>> synchronized(this){
>>> System.out.println( x );
>>> }
>>> }
>>> }
> .According to JLS ,
> "Each action in a thread happens-before every action in that thread that
> comes later in the program order".
>
> so the println out only have one result :20
>
>
This is not correct. In the examples, as I gave them, there is a write
in the constructor of 10 to the field x. That write is in a data race
with this read of x. Therefore, the read can see 10, as well.
Jeremy
More information about the Concurrency-interest
mailing list