Created
September 28, 2009 12:58
-
-
Save madebysofa/195409 to your computer and use it in GitHub Desktop.
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
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