NSLock

Basic mutex-based lock for thread synchronization in mulle-objc. Note that this may be too heavyweight for very contested locks - consider using mulle_thread_mutex_t directly in such cases.

Base Class

NSObject

Implemented Protocols

Instance Variables

mulle_thread_mutex_t    _lock;  // The underlying mutex

Methods

All methods are marked with MULLE_OBJC_THREADSAFE_METHOD:

Initialization

Locking Operations

Usage Example

NSLock *lock = [NSLock new];

// Basic locking
[lock lock];
// ... critical section ...
[lock unlock];

// Using convenience macro
MulleObjCLockDo( lock)
{
   // ... critical section ...
}  // automatically unlocked

// Try lock without blocking
if ([lock tryLock])
{
   // ... got the lock ...
   [lock unlock];
}

// Lock with timeout
if ([lock lockBeforeTimeInterval:1.0])
{
   // ... got the lock ...
   [lock unlock];
}

Important Notes

  1. Thread Safety
  2. Performance Considerations
  3. Platform Specifics