Atomic increment on mac OS X

后端 未结 4 2055
天命终不由人
天命终不由人 2021-02-06 10:10

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 poi

4条回答
  •  孤城傲影
    2021-02-06 10:41

    What makes you think OSAtomic is kernel space only? The following compiles and works fine.

    #include 
    #include 
    
    int main(int argc, char** argv) {
      int32_t foo = 1;
      OSAtomicDecrement32(&foo);
      printf("%d\n", foo);
    
      return 0;
    }
    

提交回复
热议问题