Skip to content

Instantly share code, notes, and snippets.

@tai2
Created October 12, 2012 22:51
Show Gist options
  • Save tai2/3882089 to your computer and use it in GitHub Desktop.
Save tai2/3882089 to your computer and use it in GitHub Desktop.
test how many nateve threads the platform can create
#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