objective-catomicboolean

Is BOOL read/write atomic in Objective C?


What happens when two threads set a BOOL to YES "at the same time"?


Solution

  • No. Without a locking construct, reading/writing any type variable is NOT atomic in Objective C.

    If two threads write YES at the same time to a BOOL, the result is YES regardless of which one gets in first.

    Please see: Synchronizing Thread Execution