Skip to content

Instantly share code, notes, and snippets.

@madebysofa
Created September 28, 2009 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madebysofa/195409 to your computer and use it in GitHub Desktop.
Save madebysofa/195409 to your computer and use it in GitHub Desktop.
int main (int argc, const char * argv[]) {
dispatch_queue_t waitingChairs = dispatch_queue_create("com.madebysofa.waitingChairs", 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create((long)3);
NSInteger index = -1;
while (YES) {
index++;
long success = dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW);
if (success != 0) {
NSLog(@"Customer turned away %i", index);
continue;
}
dispatch_async(waitingChairs, ^{
dispatch_semaphore_signal(semaphore);
NSLog(@"Shave and a haircut %i", index);
});
}
dispatch_release(waitingChairs);
dispatch_release(semaphore);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment