Created
May 13, 2010 04:34
-
-
Save sandofsky/399496 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
void *dumb_thread(); | |
main(int argc, char *argv[]) | |
{ | |
int total = atoi(argv[1]); | |
int concurrency = atoi(argv[2]); | |
pthread_t pthread[concurrency]; | |
int i; | |
int j; | |
for(i = 0; i < total ; i++){ | |
for(j = 0; j < concurrency; j++){ | |
pthread_create(&pthread[j], NULL, dumb_thread, NULL); | |
} | |
for(j = 0; j < concurrency; j++){ | |
pthread_join(pthread[j], NULL); | |
} | |
} | |
exit(0); | |
} | |
void *dumb_thread(){ | |
} | |
/* | |
gcc -lpthread threadtest.c -o threadtester | |
time ./threadtester 400 1000 | |
real 0m13.224s | |
user 0m1.754s | |
sys 0m9.383s | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment