On Mon, Oct 22, 2007 at 12:07:20 +0100, Dave Korn wrote: > And even volatile wouldn't help if the code said > > if (i > x) > var += i; > > instead of a simple assignment. The race in fact *does* exist in the original > program, but is hidden by the fact that you don't care which of two operations > that overwrite the previous value complete in which order, but you're assuming > the operation that modifies var is atomic, and there's nothing to innately > guarantee that in the original program. The race condition *is* already > there.
Why? For that example, if executed verbatim, it is either i > x always false, or the mutex is properly acquired. No one is assuming atomic update. -- Tomash Brechko