let's have thread-safe compare-and-swap function like long cas(long * dest ,long val ,long cmp) compares dest , cmp , copies val dest if comparison succesful , returns original value of dest atomically. so ask if code below thread-safe. while(true) { long dummy = *destvar; if(dummy == cas(destvar,value,dummy) ) { break; } } edit: dest , val parameters pointers variables created on heap. interlockedcompareexchange example out cas function. edit. edit question means of isn't relevant. still, i'll leave concerns in c# case carry c++ case, c++ case brings many more concerns stated, it's not entirely irrelevant. yes, but... assuming mean cas atomic (which case c# interlocked.compareexchange , things available use in c++ libraries) it's thread-safe in , of itself. however destvar = value thread-safe in , of (it in c#, whether in c++ or not implementation dependent). in c# write integer guaranteed atomic. such,...