Subj : Re: CAS question To : comp.programming.threads From : Toby Douglass Date : Fri Mar 25 2005 10:03 pm jseigh_01@xemaps.com wrote: > On Fri, 25 Mar 2005 19:51:32 -0000, Toby Douglass wrote: > (bad example deleted) Why was it a bad example? > > My question is: is this so? can I perform any in-line operations on the > > arguments to CAS? > > Yes but Microsoft's api is a little awkward. It's better if you have an > api that returns a boolean and updates the compare value instead. With > Microsoft's api you need to do something like > > 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. -- Toby .