Ticket #14626 (closed defect: fixed)
wxThread::Kill causes whole program to abort in Linux
| Reported by: | ZaneUJi | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | base | Version: | 2.9-svn |
| Keywords: | wxThread Kill abort NPTL | Cc: | |
| Blocked By: | Patch: | no | |
| Blocking: |
Description
After change the code:
--- samples/thread/thread0.cpp 2012-09-01 18:23:18.335144821 +0800
+++ samples/thread/thread.cpp 2012-09-01 22:46:30.617642120 +0800
@@ -360,9 +360,38 @@
m_waitingUntilAllDone = false;
}
+class BlockingThread : public wxThread
+{
+public:
+ BlockingThread() : wxThread(wxTHREAD_JOINABLE)
+ {
+ Create();
+ }
+ virtual void *Entry()
+ {
+ try {
+ char ch;
+ std::cin >> ch;
+ } catch (...) {
+ //if (TestDestroy()) {
+ throw;
+ //}
+ }
+ }
+};
+
// `Main program' equivalent, creating windows and returning main app frame
bool MyApp::OnInit()
{
+ wxThread *thread = new BlockingThread();
+ if (thread->Run() != wxTHREAD_NO_ERROR) {
+ wxLogError(wxT("Can't start thread!"));
+ }
+ wxThread::Sleep(1000);
+ thread->Kill();
+ thread->Wait();
+ delete thread;
+
// uncomment this to get some debugging messages from the trace code
// on the console (or just set WXTRACE env variable to include "thread")
//wxLog::AddTraceMask("thread");
compile it:
g++ -c -o thread.o `wx-config --cxxflags` thread.cpp g++ thread.o `wx-config --libs` -o thread
The program aborts with the following message:
terminate called without an active exception Aborted (core dumped)
When I comment out the call to pthread_exit
--- src/unix/threadpsx0.cpp Sat Sep 01 22:33:15 2012
+++ src/unix/threadpsx.cpp Sat Sep 01 21:28:33 2012
@@ -806,11 +806,12 @@
else
{
// terminate the thread
+ void *ret = pthread->m_exitcode;
thread->Exit(pthread->m_exitcode);
- wxFAIL_MSG(wxT("wxThread::Exit() can't return."));
+ //wxFAIL_MSG(wxT("wxThread::Exit() can't return."));
- return NULL;
+ return ret;//NULL;
}
}
@@ -1502,9 +1503,9 @@
}
// terminate the thread (pthread_exit() never returns)
- pthread_exit(status);
+ //pthread_exit(status);
- wxFAIL_MSG(_T("pthread_exit() failed"));
+ //wxFAIL_MSG(_T("pthread_exit() failed"));
}
// also test whether we were paused
everything works just fine.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

