April 1, 2005

Interlocked.Exchange Hazard

object box = (object)m_StitchState;
System.Threading.Interlocked.Exchange(ref box, (int)StitchState.ImageProcessing); // WILL NOT work. 
The box copes the value type object into the box, it does not create a reference that points/refers to the location of the original value or at least we cant assume it does.

No comments: