Detects unsynchronized access to mutable state across multiple threads.
- Xcode 8.0+
This check detects when multiple threads access the same memory without synchronization and at least one access is a write.
Data Race with Producer and Consumer Functions
In the following example, the
producer() function sets the global variable
message, and the
consumer() function waits for a flag to be set before printing the message. Because
producer() is executed on one thread and
consumer() is executed on another thread, order cannot be guaranteed, creating a data race.
Use Dispatch APIs to coordinate access to
message across multiple threads.