[concurrency-interest] Problems understanding "visibility"

Jeremy Manson jmanson at cs.purdue.edu
Wed Oct 19 15:33:14 EDT 2005

Jeremy Manson wrote:

> You could equally construct situations where you get ordering without 
> visibility, but I think this illustrates the point.

I'll elaborate.  Here's an example where you can get ordering without 

boolean done = false;

Thread 1:
while (!done) {
  // do  stuff

Thread 2:
done = true;

Let's say a compiler sees that Thread 1 never changes the value of done, 
and so changes Thread 1 to:

Thread 1:
while (true) {
   // do stuff

In the previous example, the order of operations had changed: the third 
write was effectively moved to the beginning of Thread 1.

In this example, the order of operations has not changed; the write by 
Thread 2 is just not visible to Thread 1.

Obviously, ordering and visibility are related, which is why acquires 
and releases provide both.  I've said myself that there is a thin line 
between the two.  The distinction can be useful when discussing these 
issues, though.


More information about the Concurrency-interest mailing list