Skip to content

Instantly share code, notes, and snippets.

@sandofsky
Created May 13, 2010 04:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sandofsky/399496 to your computer and use it in GitHub Desktop.
#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