N
Neel
Hi,
I 'm facing some prob with creating pthreads.
My requirement is to create threads in a loop.
but I dont want to make an array of pthread.
At anytime I want to have 5 threads (I used a global variable as a
counter).
Whenever the counter is less than 5, I want to create new thread.
whenever any thread is about to terminate, I will decrement the
counter. (of course avoiding race conditions using mutex lock).
But 'm confused how to create thread at run time.
I tried something like
pthread_mutex_lock(&check_thread_count);
if(threadCounter<5){
pthread_create(new pthread(), NULL, handleConnection, NULL);
}
pthread_mutex_unlock(&check_thread_count);
using *new pthread()* is not correct.
So how can I create pthread at run time?
I 'm facing some prob with creating pthreads.
My requirement is to create threads in a loop.
but I dont want to make an array of pthread.
At anytime I want to have 5 threads (I used a global variable as a
counter).
Whenever the counter is less than 5, I want to create new thread.
whenever any thread is about to terminate, I will decrement the
counter. (of course avoiding race conditions using mutex lock).
But 'm confused how to create thread at run time.
I tried something like
pthread_mutex_lock(&check_thread_count);
if(threadCounter<5){
pthread_create(new pthread(), NULL, handleConnection, NULL);
}
pthread_mutex_unlock(&check_thread_count);
using *new pthread()* is not correct.
So how can I create pthread at run time?