pthread_join 은 자원 이 제때에 방출 될 수 있 는 지 직접 결정 합 니 다.
3178 단어 pthread
/*http://hankjin.blog.163.com/blog/static/33731937201072675024100/
pthread
# cc thread.c -lpthread
# ./a.out
1 threads created
101 threads created
201 threads created
301 threads created
ERROR, rc is 11, so far 382 threads created
Fail:: Resource temporarily unavailable
, , run , pthread_exit , , , , pthread_exit , pthread_create pthread_join 。 pthread_join, pthread_exit, 。
pthread_exit , ,pthread_join 。
*/
#include<pthread.h>
#include<stdio.h>
void *run(void*p) {
pthread_exit(0); // ,
}
int main () {
pthread_t thread;
int rc;
long count = 0;
while(1) {
if((rc=pthread_create(&thread, NULL, run,NULL))!=0) {
printf("ERROR, rc is %d, %ld threads created
", rc, count);
perror("Fail:");
return -1;
}
//pthread_join(thread,0);// , id 。
if(count++%100==0)
printf("%ld threads created
", count);
}
return 0;//
}