[Previous] [Up] [Next]

NSLock

Authors

Adam Fedor

Version: $Revision$

Date: $Date$

NSLock

NSLock

Declared in: Foundation/NSLock.h

Inherits from: NSObject

Conforms to: NSLocking


An NSLock is used in multi-threaded applications to protect critical pieces of code. While one thread holds a lock within a piece of code, another thread cannot execute that code until the first thread has given up it's hold on the lock. The limitation of NSLock is that you can only lock an NSLock once and it must be unlocked before it can be aquired again. Other lock classes, notably NSRecursiveLock, have different restrictions.

Instance Variables

Methods


Instances Methods

lockBeforeDate:

- (BOOL) lockBeforeDate: (NSDate*)limit;
Attempts to aquire a lock before the date limit passes. It returns YES if it can. It returns NO if it cannot, or if the current thread already has the lock (but it waits until the time limit is up before returning NO).

tryLock

- (BOOL) tryLock;
Attempts to aquire a lock, but returns immediately if the lock cannot be aquired. It returns YES if the lock is aquired. It returns NO if the lock cannot be aquired or if the current thread already has the lock.