Subj : Re: CAS question To : comp.programming.threads From : Toby Douglass Date : Fri Mar 25 2005 10:30 pm jseigh_01@xemaps.com wrote: > On Fri, 25 Mar 2005 22:03:55 -0000, Toby Douglass wrote: > It was incorrect usage. The example I gave was the correct usage. Incorrect in what way? > >> oldcount = count; > >> while ((oldcount = InterlockedCompareExchange(&count, oldcount + 1, cmpcount = oldcount)) != cmpcount); > > > > The "cmpcount = oldcount" assignment for the third argument is atomic > > because it's one of the arguments to InterlockedCompareExchange()? > > > > It might be that within the algorithm in use, that assignment doesn't > > need to be atomic, which is fine, but surely that assignment is cannot > > be atomic because it is performed as the argument to the function call. > The argument expressions are evaluated before the function is called. They > don't have to be atomic or anything. Is this true in all cases, though? I don't know x86, but I could imagine that something simple like an addition or subtraction could be performed in situ on an operand to the atomic instruction. In a hardware sense, it would just be a case of getting a ALU to perform an operation on an operand as it passes down the pipeline, which seems reasonable. -- Toby .