Skip to content

Instantly share code, notes, and snippets.

@tjw
Created September 10, 2009 03:40
Show Gist options
  • Save tjw/184272 to your computer and use it in GitHub Desktop.
Save tjw/184272 to your computer and use it in GitHub Desktop.
#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.
;
});
}
dispatch_main();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment