summaryrefslogtreecommitdiff
path: root/Examples/test-suite/director_thread.i
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2017-05-12 08:20:01 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2017-05-12 18:57:37 +0100
commitbe5d046f7dc1c761e0308e1c75f6286cd76cdff4 (patch)
tree443573914b5cc7a202bdbd02d10e98ca9e5244a2 /Examples/test-suite/director_thread.i
parente8e56f74ca5b12ca335c6db7319fbc1e0fc1b387 (diff)
downloadswig-be5d046f7dc1c761e0308e1c75f6286cd76cdff4.tar.gz
director_thread testcase improvements
- Add missing threading constructs to director_thread test for Windows - pthreads tidy up
Diffstat (limited to 'Examples/test-suite/director_thread.i')
-rw-r--r--Examples/test-suite/director_thread.i28
1 files changed, 17 insertions, 11 deletions
diff --git a/Examples/test-suite/director_thread.i b/Examples/test-suite/director_thread.i
index fa55540a0..699ccf5c4 100644
--- a/Examples/test-suite/director_thread.i
+++ b/Examples/test-suite/director_thread.i
@@ -11,6 +11,7 @@
#ifdef _WIN32
#include <windows.h>
#include <process.h>
+#include <stdio.h>
#else
#include <pthread.h>
#include <signal.h>
@@ -22,11 +23,11 @@
class Foo;
extern "C" {
#ifdef _WIN32
- unsigned int __stdcall working(void* t);
- unsigned int thread_id(0);
+ static unsigned int __stdcall working(void* t);
+ static HANDLE thread_handle = 0;
#else
void* working(void* t);
- pthread_t thread;
+ static pthread_t thread;
#endif
static int thread_terminate = 0;
@@ -66,7 +67,8 @@ extern "C" {
void stop() {
set_thread_terminate(1);
%#ifdef _WIN32
- /*TODO(bhy) what to do for win32? */
+ WaitForSingleObject(thread_handle, INFINITE);
+ CloseHandle(thread_handle);
%#else
pthread_join(thread, NULL);
%#endif
@@ -74,9 +76,18 @@ extern "C" {
void run() {
%#ifdef _WIN32
- _beginthreadex(NULL,0,working,this,0,&thread_id);
+ int thread_id = 0;
+ thread_handle = (HANDLE)_beginthreadex(NULL,0,working,this,0,&thread_id);
+ if (thread_handle == 0) {
+ fprintf(stderr, "_beginthreadex failed in run()\n");
+ assert(0);
+ }
%#else
- pthread_create(&thread,NULL,working,this);
+ int create = pthread_create(&thread,NULL,working,this);
+ if (create != 0) {
+ fprintf(stderr, "pthread_create failed in run()\n");
+ assert(0);
+ }
%#endif
MilliSecondSleep(500);
}
@@ -100,11 +111,6 @@ extern "C" {
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;
}
}