I have googled for atomic increment and decrement operators on Mac OS X and found "OSAtomic.h", but it seems you can only use this in kernel space.
Jeremy Friesner pointed me at a cross-platform atomic counter in which they use assembly or mutex on OS X (as far as I understood the interleaving of ifdefs).
Isn't there something like InterlockedDecrement
or atomic_dec()
on OS X ?
What makes you think OSAtomic is kernel space only? The following compiles and works fine.
#include <libkern/OSAtomic.h>
#include <stdio.h>
int main(int argc, char** argv) {
int32_t foo = 1;
OSAtomicDecrement32(&foo);
printf("%d\n", foo);
return 0;
}
Currently, the recommendation is to use C++11's std::atomic
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With