Interlocked operations in iOS?

前端 未结 4 747
感动是毒
感动是毒 2021-01-04 08:11

Are there interlocked(atomic) operations in iOS SDK?

I need interlocked increment\\decrement and interlocked comparsion.

*UPDATE: * My main proble

4条回答
  •  清歌不尽
    2021-01-04 08:48

    Objective-C has the keyword synchronized for atomic operations.

    @synchronized(object) {
        // ...
    }
    

    If you specify the attribute atomic in a property declaration, the setters and getters will be sythesized using these synchronized-blocks.

    Also look at NSLock and NSLocking protocol.

提交回复
热议问题