From 9fca02fbdf53f1a10550c8bcccc67363f89d4993 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Aug 2006 22:09:46 +0000 Subject: [PATCH] This is file is not new, it has been moved from the python subdirectory so it can be used by all language modules git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9241 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/director_thread.i | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 SWIG/Examples/test-suite/director_thread.i diff --git a/SWIG/Examples/test-suite/director_thread.i b/SWIG/Examples/test-suite/director_thread.i new file mode 100644 index 000000000..5c1acdb0f --- /dev/null +++ b/SWIG/Examples/test-suite/director_thread.i @@ -0,0 +1,47 @@ +%module(directors="1",threads="1") director_thread + +%{ +#include +#include + +class Foo; +extern "C" void* working(void* t); +%} + +%director Foo; + +%inline { + class Foo { + public: + int val; + pthread_t *t; + + Foo() : val(0) { + t = new pthread_t; + } + + virtual ~Foo() { + delete t; + } + + void run() { + pthread_create(t,NULL,working,this); + sleep(5); + } + + virtual void do_foo() { + val += 1; + } + }; +} + +%inline { + extern "C" void* working(void* t) { + Foo* f = static_cast(t); + while (1) { + sleep(1); + f->do_foo(); + } + return 0; + } +}