[concurrency-interest] synchronized on construction

Jeremy Manson jmanson at cs.purdue.edu
Fri May 26 10:01:32 EDT 2006

Thomas Hawtin wrote:
> Jeremy Manson wrote:
>> Thomas Hawtin wrote:
>>> Jeremy Manson wrote:
>>>> If you don't have that synchronization in your code, then there you 
>>>> have a bug.  A data race.  Data races rot the brain and corrupt the 
>>>> soul.
>>> Yeah but my soul is already corrupt and my brain nicely folded.
>> ... and I'm sure your clients appreciate when that comes out in your code!
> Clients?

As in, anyone who uses code you write.  Just a little levity.

> As I'm sure you are aware, most normal people find it very difficult to 
> interpret Chapter 17. Applying the rules directly is difficult. Roach 
> motel is all well and good, but if it isn't exact, how do I know the set 
> of possible things that could go wrong? As someone trying to ensure the 
> absence of bugs, I don't care what a compiler can do but what it cannot.

I am aware of this.  Roach motel is really a rule of thumb for compiler 
writers more than for working programmers.

Working programmers should try to think about these properties in terms 
of happens-before, which is exact, and, although a little tricky, is 
actually a pretty good abstraction once you wrap your mind around it. 
In the example we were discussing, if the read happens-before the write, 
the read is guaranteed not to see the write.  Therefore, the compiler 
cannot move it to a place where the read might see it.


More information about the Concurrency-interest mailing list