diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2006-08-16 20:51:50 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2006-08-16 20:51:50 +0000 |
commit | ba8acb59a73446730bdbb12b06f3757c46b45550 (patch) | |
tree | 4904bf9085b8b6617409b3bcef542f1f5434b88e /Examples/test-suite/director_thread.i | |
parent | 907491072c98cae81449fd5bf8ffaaa3de43008b (diff) | |
download | swig-ba8acb59a73446730bdbb12b06f3757c46b45550.tar.gz |
Fix win32 threads
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9253 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/test-suite/director_thread.i')
-rw-r--r-- | Examples/test-suite/director_thread.i | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/Examples/test-suite/director_thread.i b/Examples/test-suite/director_thread.i index 4e792858c..4f4e55cfe 100644 --- a/Examples/test-suite/director_thread.i +++ b/Examples/test-suite/director_thread.i @@ -20,7 +20,13 @@ class Foo; extern "C" { - void* SWIGSTDCALL working(void* t); +#ifdef _WIN32 + unsigned int __stdcall working(void* t); + unsigned int thread_id(0); +#else + void* working(void* t); + pthread_t thread; +#endif } %} @@ -28,34 +34,30 @@ extern "C" { %inline { static void MilliSecondSleep(int milliseconds) { - #ifdef _WIN32 + %#ifdef _WIN32 Sleep(milliseconds); - #else + %#else usleep(milliseconds*1000); - #endif + %#endif } class Foo { public: int val; - pthread_t *t; - unsigned int thread_id; - Foo() : val(0), thread_id(0) { - t = new pthread_t; + Foo() : val(0) { } virtual ~Foo() { - delete t; } void run() { -#ifdef _WIN32 - _beginthreadex(NULL,0,run,this,0,&thread_id); -#else - pthread_create(t,NULL,working,this); -#endif - MilliSecondSleep(5000); +%#ifdef _WIN32 + _beginthreadex(NULL,0,working,this,0,&thread_id); +%#else + pthread_create(&thread,NULL,working,this); +%#endif + MilliSecondSleep(500); } virtual void do_foo() { @@ -64,12 +66,17 @@ extern "C" { }; } -%inline %{ - extern "C" { - void* working(void* t) { +%{ +extern "C" { +#ifdef _WIN32 + unsigned int __stdcall working(void* t) +#else + void* working(void* t) +#endif + { Foo* f = static_cast<Foo*>(t); while (1) { - MilliSecondSleep(1000); + MilliSecondSleep(50); f->do_foo(); } return 0; |