[wx 2.6.3, WinXP] Thread Issues In Console Application

Jul jul6789 at yahoo.com
Thu Aug 10 21:29:12 PDT 2006


In the process of upgrading a large console
application that previously used wx 2.4.2, I have
discovered two serious issues with threads in wx
2.6.3. After a lot of research, I have found what I
believe are solutions to the problems, so I thought I
would post my findings in the event it might help
someone else experiencing the same issue.

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);

Removing it made everything work fine for me - no
stuck threads. On a whim, I checked thread.cpp in the
2.7.0 release and noticed that this line has indeed
been removed. Most people will be using 2.6.3 since
it's the release version and a 2.8.x release is a
while off. A stuck thread seems pretty major to me ...
so perhaps a patch for 2.6.3 is in order?

The second problem I encountered were two error
messages being generated when threads were exiting. No
such messages appeared in wx 2.4.2 with the exact same
code. Here are the messages:
23:57:42: Error: Can not wait for thread termination
(error 6: the handle is invalid.)
23:57:42: Error: Couldn't terminate thread (error 6:
the handle is invalid.)

After examining the source for wxThread, we discovered
that these were being generated because we were
incorrectly calling both Delete() and Wait() on our
joinable threads to terminate them. The instructions
for correctly terminating threads were vague in
2.4.2's documentation (and 2.6.3 too) which led us to
believe we needed to call both to properly terminate a
thread. It's now obvious that you should only call
Wait() on a joinable thread to terminate it, but the
documentation set that comes with 2.4.2 and 2.6.3
definitely miss this point. We looked at the
documentation from the latest build, which I assume is
associated with 2.7.0, and discovered that the
documentation for Wait() and Destroy() has been
updated to reflect their distinct roles in gracefully
terminating joinable and detachable threads
respectively.

The updated documentation is great, but we'd like to
suggest that a reference to the two methods of
terminating threads be placed in the wxThread
introduction itself. The second and third paragraphs
would be an ideal place for it. It's also too bad that
this change wasn't made to the documentation for
2.6.3.

Hopefully this will help someone. Also, pardon me if
this has been addressed before but I couldn't find any
references to these specific problems in the forum or
the mailing list archive.

wxWidgets is great! :)

Thanks,
   Jul

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the wx-users mailing list