Created
September 10, 2009 03:40
-
-
Save tjw/184272 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
#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