From the doc, atomicCAS
returns the old value, that means, that in your list, your two outcomes are wrong. Your X
will always be set to the old value of localMap[fn]
, regardless which value it had. What is set according to the comparison with the -1, is the new value of localMap[fn]
. When it is -1, it is set to rnumber
, else it is left intact.
So the behaviour you see with the values of X
, rnumber
and localMap
are as expected.
I cannot help with your second problem, as I dont use NSight, and dont know how it works - according to your code, your true branch should be evaluated (but be careful: your false branch also - as it is multi threaded some threads can have the condition evaluated to true, and some to false - my guess/assumption would be that you must tell somehow your debugger which thread/warp/block you want to debug and you looked at the false).