Atomically get value on Mac OS
I need some function to atomi开发者_如何学运维cally get int value. Something called OSAtomicGet(). Analog of g_atomic_int_get().
Dereferencing an int
from a known pointer is always atomic on architectures running Mac/iStuffs. Use OSMemoryBarrier() if you need a memory barrier.
int OSAtomicGet(volatile int* value) {
OSMemoryBarrier();
return *value;
}
精彩评论