Question

I need some function to atomically get int value. Something called OSAtomicGet(). Analog of g_atomic_int_get().

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top