Thread synchronization primitive that combines mutex and condition variable functionality. Provides low-level thread coordination.
NSObject
#ifndef _WIN32
pthread_mutex_t _lock; // Mutex for synchronization
pthread_cond_t _condition; // Condition variable
#endif
-lock
- Acquires the lock-unlock
- Releases the lock-tryLock
- Attempts to acquire lock without blocking-signal
- Wakes one waiting thread-broadcast
- Wakes all waiting threads-wait
- Waits for signal (must be locked)@property name
- Condition name (for debugging)@property(readonly) mulleIsLocked
- Lock state// Create condition
NSCondition *condition = [[NSCondition alloc] init];
// Producer thread
[condition lock];
// ... modify shared state ...
[condition signal]; // or [condition broadcast];
[condition unlock];
// Consumer thread
[condition lock];
while (!readyToProcess) {
[condition wait];
}
// ... process shared state ...
[condition unlock];
// Try lock without blocking
if ([condition tryLock]) {
// ... critical section ...
[condition unlock];
}