|
From: | Krishna, Samaga |
Subject: | Need help on Pthead_create |
Date: | Fri, 15 Oct 2004 17:25:18 +0530 |
Hi
I do not know whether it is bug or some thing wrong with my system
I am using GUN DDD 3.2.1 (i686-pc-linux-gnu) Compiling the code using gcc ( 2.96)
I had written a function using pthread_create. If I run this with out using the ddd I could run the function in a loop for 2000 times. But when I use the ddd after 1010 times the pthread_create will return an error and program exits. It is due to non availability of threads. I wonder how a code can run well with our ddd and using ddd has issues.
Do help me out to figure the problem
Thanks in advance Prasanna
The code I had written is as follows
#include<stdio.h> #include<pthread.h> #include<error.h> int num=0;
void returnFun() { int retval; printf("The function is called =%d times\n", num++); }
main() {
pthread_t tid; pthread_attr_t attr; int i;
printf("This is a function to test Pthread_create and exit functions\n");
for(i=0;i<2000;i++) { if(pthread_attr_init(&attr) != 0) { printf("Failed to initialize thread attributes for the new thread!\n"); return; } if(pthread_attr_setschedpolicy(&attr,0) != 0) { printf("failed to initialize set the scheduling policy for the new thread!\n"); return; }
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if(pthread_create(&tid,&attr, (void*)&returnFun,NULL) != 0) { printf("not enough resources to create the thread!\n"); return;
}
}
} |
[Prev in Thread] | Current Thread | [Next in Thread] |