Is there any posix/thread related API that could help to make “a value change operation” thread-safe, without locking several statements?
Is there a posix API for Linux to do this?
Advertisement
Answer
GCC has atomic built-ins, __sync_val_compare_and_swap
should be equivalent of InterLockedCompareExchange
If you use C++ 11, you can use std::atomic_compare_exchange_*
in atomic operations library as needed.