Selçuk Cihan
2009-05-09 16:09:24 UTC
Hi all, i am puzzled with the behaviour of my multithreaded application.
I start a detached wxThread for a certain event, and there is at most one
such thread at any time. After the worker thread starts, it starts doing its
task corresponding to the event. And then, if another such event is caught,
the code checks if the thread is running and if it is running it pushes the
new task(corresponding to the new event) to the task queue of the thread.
Access to the task queue is protected via a critical section.
To be able to push new tasks to the queue, GUI thread needs to control
deletion of the worker thread. For that, i post a "delete me" event to GUI
as soon as there are no jobs on the task queue and then GUI calls
thread->Delete() in the "delete me" event handler.
The thread has the main loop while(!TestDestroy()) { get task; do task; }
GUI's "delete me" event handler just does this:
thread->Delete();
thread = 0; /* to be able to determine later if the thread is running or not
*/
Now, the problem is, the execution never arrives at the above line that sets
thread to zero.
Having explained the problem, i wrote a minimal implementation for the above
thread behaviour and guess what, the execution does arrive at thread = 0
line, no problems. So i figure out the problem is not related to the
behaviour / logic explained in the beginning.
I am messing things up somewhere but i haven't been able to detect the cause
of the problem yet.
What would be the reason that, execution does not reach the line after
thread->Delete() ? By the way, the gui is not blocking after Delete() and
other things seem to go fine (gui catches events just fine).
Also, the thread actually gets destroyed and i can see its TestDestroy()
return false and its OnExit() function being reached.
Any ideas truely appreciated
I start a detached wxThread for a certain event, and there is at most one
such thread at any time. After the worker thread starts, it starts doing its
task corresponding to the event. And then, if another such event is caught,
the code checks if the thread is running and if it is running it pushes the
new task(corresponding to the new event) to the task queue of the thread.
Access to the task queue is protected via a critical section.
To be able to push new tasks to the queue, GUI thread needs to control
deletion of the worker thread. For that, i post a "delete me" event to GUI
as soon as there are no jobs on the task queue and then GUI calls
thread->Delete() in the "delete me" event handler.
The thread has the main loop while(!TestDestroy()) { get task; do task; }
GUI's "delete me" event handler just does this:
thread->Delete();
thread = 0; /* to be able to determine later if the thread is running or not
*/
Now, the problem is, the execution never arrives at the above line that sets
thread to zero.
Having explained the problem, i wrote a minimal implementation for the above
thread behaviour and guess what, the execution does arrive at thread = 0
line, no problems. So i figure out the problem is not related to the
behaviour / logic explained in the beginning.
I am messing things up somewhere but i haven't been able to detect the cause
of the problem yet.
What would be the reason that, execution does not reach the line after
thread->Delete() ? By the way, the gui is not blocking after Delete() and
other things seem to go fine (gui catches events just fine).
Also, the thread actually gets destroyed and i can see its TestDestroy()
return false and its OnExit() function being reached.
Any ideas truely appreciated