Skip to content

Instantly share code, notes, and snippets.

Created Sep 10, 2009
What would you like to do?
#import <stdio.h>
#import <dispatch/dispatch.h>
#import <libkern/OSAtomic.h>
#import <unistd.h>
gcc-4.2 -arch x86_64 -std=gnu99 -O0 -mdynamic-no-pic -Wall -Werror -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -gdwarf-2 max-concurrent.c -o max-concurrent
int main(int argc, char *argv[])
static int32_t CurrentRunning = 0;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
for (int32_t i = 0; i < 100; i++) {
dispatch_async(queue, ^{
int32_t running = OSAtomicIncrement32(&CurrentRunning);
fprintf(stderr, "running %d\n", running);
while (1)
sleep(1) // without the sleep (just a spin loop), only #core ops will be started. with it, the full batch will start.
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment