Created
October 12, 2012 22:51
-
-
Save tai2/3882089 to your computer and use it in GitHub Desktop.
test how many nateve threads the platform can create
This file contains hidden or 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 * | |
thread_func(void *p) | |
{ | |
for(;;); | |
return NULL; | |
} | |
int | |
main() | |
{ | |
pthread_attr_t attr; | |
pthread_t id; | |
int loop = 1; | |
int cnt = 0; | |
while (loop) { | |
pthread_attr_init(&attr); | |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
if (pthread_create(&id, &attr, thread_func, NULL) == 0) { | |
cnt++; | |
} else { | |
loop = 0; | |
} | |
pthread_attr_destroy(&attr); | |
} | |
printf("%d threads created\n", cnt); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment