the documentation does not say what happens when the expected oldval
and the newval
is the same. Following is from the gcc doc:
The “bool” version returns true if the comparison is successful and newval is written.
So if the newval and oldval is the same, effectively there is no write. So will following code always returns true if the *ptr == 0
?
__sync_bool_compare_and_swap(&ptr, 0, 0)
Thanks