Fix problem caused by thread not properly terminated in director_thread test. This was cause crash in Python 3
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11161 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a863d31e81
commit
0c5979a8d8
2 changed files with 20 additions and 1 deletions
|
|
@ -13,6 +13,7 @@
|
|||
#include <process.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -27,6 +28,8 @@ extern "C" {
|
|||
void* working(void* t);
|
||||
pthread_t thread;
|
||||
#endif
|
||||
static int thread_terminate = 0;
|
||||
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
@ -51,6 +54,15 @@ extern "C" {
|
|||
virtual ~Foo() {
|
||||
}
|
||||
|
||||
void stop() {
|
||||
thread_terminate = 1;
|
||||
%#ifdef _WIN32
|
||||
/*TODO(bhy) what to do for win32? */
|
||||
%#else
|
||||
pthread_join(thread, NULL);
|
||||
%#endif
|
||||
}
|
||||
|
||||
void run() {
|
||||
%#ifdef _WIN32
|
||||
_beginthreadex(NULL,0,working,this,0,&thread_id);
|
||||
|
|
@ -75,10 +87,15 @@ extern "C" {
|
|||
#endif
|
||||
{
|
||||
Foo* f = static_cast<Foo*>(t);
|
||||
while (1) {
|
||||
while ( ! thread_terminate ) {
|
||||
MilliSecondSleep(50);
|
||||
f->do_foo();
|
||||
}
|
||||
#ifdef _WIN32
|
||||
/* TODO(bhy) what's the corresponding of pthread_exit in win32? */
|
||||
#else
|
||||
pthread_exit(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,3 +14,5 @@ d.run()
|
|||
if d.val >= 0:
|
||||
print d.val
|
||||
raise RuntimeError
|
||||
|
||||
d.stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue