views:

39

answers:

1

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

+2  A: 

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;
}
KennyTM
Thank you very much!
iUm