Im working with pthreads in my c code. I create and start a thread (THREAD_1) in my main routine, where from THREAD_1, I call a routine to开发者_JAVA百科 create again two new threads (THREAD_2, THREAD_3). All the three thread will be running parallel with milliseconds sleep in a conditional loop. After a certain condition is met I want to stop/exit the two threads (THREAD_2, THREAD_3) and then THREAD_1. What is the best way to do this?
while(true){
apr_thread_mutex_lock(mySharedObject->getMutex());
while (mySharedObject->getMessagesReady() == 0 && !mySharedObject->getEndThread()) {
apr_thread_cond_wait(mySharedObject->getCond(), mySharedObject->getMutex());
}
if (mySharedObject->getEndThread()){
apr_thread_mutex_unlock(mySharedObject->getMutex());
break;
}
apr_thread_mutex_unlock(mySharedObject->getMutex());
if (mySharedObject->getMessagesReady()>0){
myActiveProducer->send();
}
}
This is the way that I've implemented it. Something wrong??
精彩评论