Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interlocked operations in iOS?

Are there interlocked(atomic) operations in iOS SDK?

I need interlocked increment\decrement and interlocked comparsion.

*UPDATE: * My main problem is waiting for few NSThreads created by main thread(main thread mustn't work while other threads work).

I don't know how to do it.

like image 969
Siarhei Fedartsou Avatar asked Feb 01 '11 12:02

Siarhei Fedartsou


2 Answers

You can use the OSAtomicIncrement*/OSAtomicDecrement* operations described in Using Atomic Operations.

like image 182
Georg Fritzsche Avatar answered Oct 23 '22 20:10

Georg Fritzsche


Update: Language level atomics under C11 and C++11 are now available.

You can simply declare _Atomic(int) a;.

A more detailed introduction.


atomic operations and their documentation can be found in libkern/OSAtomic.h. an overview can be found under man atomic.

as well, you will likely find C11 and C++11 language/library support very soon.

like image 2
justin Avatar answered Oct 23 '22 18:10

justin