Skip to content

Instantly share code, notes, and snippets.

@EverythingSolution
Created August 27, 2011 19:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EverythingSolution/1175800 to your computer and use it in GitHub Desktop.
Save EverythingSolution/1175800 to your computer and use it in GitHub Desktop.
Basic Dispatch Sync
@implementation ThreadyMcThreaderson
{
dispatch_queue_t _syncQueue;
}
- (id)init
{
self = [super init];
if (self)
{
_syncQueue = dispatch_queue_create("com.doug.syncygoodness", 0);
}
return self;
}
- (void)dealloc
{
dispatch_release(_syncQueue);
#if !__has_feature(objc_arc)
[super dealloc];
#endif
}
- (void)doSomethingSyncy
{
// You could
@synchronized(self)
{
}
// But you should
dispatch_sync(_syncQueue, ^(void) {
// This is your critical section
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment