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_l ock(&check_thre ad_count);
if(threadCounte r<5){
pthread_create( new pthread(), NULL, handleConnectio n, NULL);
}
pthread_mutex_u nlock(&check_th read_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_l ock(&check_thre ad_count);
if(threadCounte r<5){
pthread_create( new pthread(), NULL, handleConnectio n, NULL);
}
pthread_mutex_u nlock(&check_th read_count);
using *new pthread()* is not correct.
So how can I create pthread at run time?
Comment