summaryrefslogtreecommitdiff
path: root/Examples/test-suite/director_thread.i
diff options
context:
space:
mode:
authorHaoyu Bai <divinekid@gmail.com>2009-03-19 16:56:01 +0000
committerHaoyu Bai <divinekid@gmail.com>2009-03-19 16:56:01 +0000
commit0c5979a8d81bf222be65ef9f21d214ca34a29b6c (patch)
treebbcecb11847847e27041629df8d927eaf5716fe7 /Examples/test-suite/director_thread.i
parenta863d31e81c8081db581d366fcce1a35cdd0bfe1 (diff)
downloadswig-0c5979a8d81bf222be65ef9f21d214ca34a29b6c.tar.gz
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
Diffstat (limited to 'Examples/test-suite/director_thread.i')
-rw-r--r--Examples/test-suite/director_thread.i19
1 files changed, 18 insertions, 1 deletions
diff --git a/Examples/test-suite/director_thread.i b/Examples/test-suite/director_thread.i
index 4f4e55cfe..2732eb907 100644
--- a/Examples/test-suite/director_thread.i
+++ b/Examples/test-suite/director_thread.i
@@ -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;
}
}