i have a daemon process that creates and joins multiple threads.
every so often the pthread error check will fail and the program terminate.
under what conditions would the pthread_create function fail?
i'm really looking for some practical reasons. i believe that the code is correct.
i'm also having problems with pthread_join hanging randomly.
any ideas?
TIA, rotis23
every so often the pthread error check will fail and the program terminate.
under what conditions would the pthread_create function fail?
i'm really looking for some practical reasons. i believe that the code is correct.
i'm also having problems with pthread_join hanging randomly.
any ideas?
TIA, rotis23
Code:
*************************************************
pthread_exit(NULL); //end of thread_function
*************************************************
int res;
int lots_of_threads;
int num_sites;
pthread_t a_thread[5];
void *thread_result;
//initialise mutex - used to synchronise linked list between threads
res = pthread_mutex_init(&queue_mutex, NULL);
if (res != 0){printf("mutex creation failure.\n");
//add multiple threads
for(lots_of_threads = 0; lots_of_threads < 5; lots_of_threads++)
{
//threads are created and started
res = pthread_create(&(a_thread[lots_of_threads]), NULL,
thread_function, (void *)lots_of_threads);
if (res != 0){printf("create failure.\n");
}
//wait for threads to finish and clean up
printf("Waiting for threads to finish...\n");
for(lots_of_threads = 5 - 1; lots_of_threads >= 0;
lots_of_threads--)
{
res = pthread_join(a_thread[lots_of_threads], NULL);
if (res == 0)
{
printf("Picked up a thread\n");
}
else{printf("join error.\n");
}