Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created September 14, 2013 02:20
Show Gist options
  • Save Superbil/6558312 to your computer and use it in GitHub Desktop.
Save Superbil/6558312 to your computer and use it in GitHub Desktop.
dispatch_group_t group = dispatch_group_create();
dispatch_semaphore_t semaphore = dispatch_semaphore_create(10);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
for (int i = 0; i < 100; i++)
{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_group_async(group, queue, ^{
NSLog(@"%i",i);
sleep(2);
dispatch_semaphore_signal(semaphore);
});
}
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
dispatch_release(group);
dispatch_release(semaphore);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment