[concurrency-interest] concurrency puzzle

David Holmes dcholmes at optusnet.com.au
Mon Sep 11 23:01:40 EDT 2006

> >
> >    int x;
> >
> >and
> >
> >    int x = 0;
> >
> >
> 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.

Sorry I don't follow. If the reading thread has not written to x then it can
only read zero. It can't tell whether it reads the "before the dawn of time"
zero, or the constructor written zero.

To me the only interesting case is when a thread does:

    foo.x = N;

and the question is under what circumstances is the print guaranteed to
print N? If the only other write to x is the default initialization of it
then in that case the print is guaranteed to print N. Otherwise the print
can print either N or whatever other value was written to x.


More information about the Concurrency-interest mailing list