[wx 2.6.3, WinXP] Thread Issues In Console Application
Joost
imim at newhouse.nl
Fri Aug 11 04:41:59 PDT 2006
Jul wrote:
> The first problem I noticed was that the joinable
> threads created by my application would occasionally
> get stuck as they were being destroyed (via the
> Destroy method). They would get stuck in an infinite
> loop inside the WaitForTerminate method in the
> wxThreadInternal class. On closer examination, it
> appears that this line of thread.cpp (line 748 in the
> msw directory) was the source of the loop:
> ::PostMessage(NULL, WM_NULL, 0, 0);
I ran into similar problems with a joinable thread. It could have been a
fault in my code, I wasn't sure, but somehow WX tried to force kill the
thread instead of just waiting for it. This workaround solved it:
Create the thread as wxTHREAD_DETACHED instead of wxTHREAD_JOINABLE, and
add two wxSemaphores. When the thread has finished its work, it signals
semaphore 1 and then waits for semaphore 2.
Instead of Wait()ing for the thread, the main thread waits for semaphore
1 and then signals semaphore 2. The thread object should not be deleted
in this case (it will clean up itself).
I guess a wxCondition would have worked too.
Joost
More information about the wx-users
mailing list