Here's how to do a mutex when writing a multithreaded Cocoa app. Use the NSLock class...
// In your class' header. (ClassName.h)
@interface ClassName: NSObject
{
NSLock* mutex;
}
// In your class' source. (ClassName.m)
@implementation ClassName
- (id)init
{
if ( (self = [super init] ) )
{
mutex = [[NSLock alloc] init];
// Other initialization stuff here..
}
return self;
}
- (void)dealloc
{
if ( mutex )
{
[mutex release];
mutex = NULL;
}
// Other cleanup code here...
[super dealloc];
}
- (void)someFunction
{
[mutex lock];
// Do some stuff.
[mutex unlock];
}