Created
August 27, 2011 19:58
-
-
Save EverythingSolution/1175800 to your computer and use it in GitHub Desktop.
Basic Dispatch Sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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