Instantly share code, notes, and snippets.

Embed
What would you like to do?
POSIX Mutex
#import <pthread/pthread.h>
@implementation TestMutex {
pthread_mutex_t mutex;
}
- (instancetype)init {
if (self = [super init]) {
// Initialize the mutex
pthread_mutex_init(&mutex, NULL);
}
return self;
}
- (void)aSynchronizedMethod {
// Acquire lock
pthread_mutex_lock(&mutex);
// Do your exclusing coding here
// Relinquish the lock once its done
pthread_mutex_unlock(&mutex);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment