Re: waiting for another thread without blocking resources...
Cholo Lennon wrote:
PS: Could you provide some code to check the library use?
boost::thread *THREAD_FileReceiver; // global variable
int GLB_listen = 0; // global
int GLB_listening = 0; // global
// event handler function
void OnToggleListen()
{
if (!GLB_listen) {
if (GLB_listening) {
cout << "error: still ending thread" << endl;
return;
}
GLB_listen = 1; // set keepalive flag for thread
cout << "starting thread" << endl;
// this function is the threads main loop, receiving UDP packets
THREAD_FileReceiver = new boost::thread(&listenForUDPFiles);
// wait for thread to set GLB_Listening := 1 - how??
// the following is the cmd button to toggle thread status
mainWindow->cmdToggleListen->SetLabel ("Stop Listening");
}
else {
if (!GLB_listening) {
cout << "error: still starting thread" << endl;
return;
}
GLB_listen = 0; // unset keepalive flag for thread
// send a UDP packet to get thread out of listening mode
sendEndOfStream();
cout << "waiting for thread to end" << endl;
THREAD_FileReceiver->join();
cout << "thread finished, GLB_listening = " << GLB_listening << endl;
delete THREAD_FileReceiver;
THREAD_FileReceiver = 0;
// the following is the cmd button to toggle thread status
mainWindow->cmdToggleListen->SetLabel ("Start Listening");
}
}
---
this code just crashes after the join() call while without it, the code
would exit normally. However, then I have a possible race condition when
re-activating the thread. Are you able to make anything from that?
Thanks,
Lars