[concurrency-interest] concurrency puzzle

Vijay Saraswat vijay at saraswat.org
Mon Sep 11 22:49:19 EDT 2006

David Holmes wrote:

>I don't claim to understand the attempted formalism of this. The difference
>    int x;
>    int x = 0;
>is that given a thread T that is reading x from an instance that was
>unsafely published, and where T first writes the value x=N, then in the
>first case the legal values for the read of x is only N, while in the second
>case it is 0 or N.
>I guess the practical consequence is that in the second case you may
>actually discover that you have a bug due to unsafe publication, while in
>the first case you likely never will. Of course it would be perfectly legal
>(probably not worth the effort) for the compiler to optimize away writes of
>default values in the constructor, such that the runtime behaviour of both
>cases is the same.
>Where do you see the potential for a huge difference?
As I said in my message, the first program fragment has no 
unsynchronized writes -- so no possibility of a race. But the second 
does. So there is a potential for a race involving a thread that reads 
the value of the variable x.

More information about the Concurrency-interest mailing list