Name
NSDistributedLock — Mac OS X 10.0
Synopsis
This class provides an interface to an object that can be used by multiple applications to control access to a shared resource (such as a file). This class works by creating an entry in the filesystem at a path known to each application that is interested in acquiring a lock to access the shared resource.
A distributed lock object is initialized
with a filesystem entry using the method
initWithPath
:. To acquire a lock, thus making it
safe to access a resource, we use the method
tryLock
. This method returns a
BOOL
indicating whether or not it was successful
in attempting to acquire a lock. To relinquish a previously acquired
lock, use the method unlock
.
|
@interface NSDistributedLock : NSObject
|
// Initializers
|
- (id)initWithPath:(NSString *)path; |
// Class Methods
|
+ (NSDistributedLock *)lockWithPath:(NSString *)path; |
// Instance Methods
|
- (void)breakLock;
|
- (NSDate *)lockDate;
|
- (BOOL)tryLock;
|
- (void)unlock;
|
Get Cocoa in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.