add director+thread case
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7147 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
56ac2ae4b1
commit
30bd3c6834
2 changed files with 51 additions and 0 deletions
40
Examples/test-suite/python/director_thread.i
Normal file
40
Examples/test-suite/python/director_thread.i
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
%module(directors="1") director_thread
|
||||
|
||||
%{
|
||||
#include <pthread.h>
|
||||
#include <iostream>
|
||||
|
||||
class Foo;
|
||||
extern "C" void* working(void* t);
|
||||
%}
|
||||
|
||||
|
||||
%feature("director") Foo;
|
||||
|
||||
%inline {
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
|
||||
void run() {
|
||||
pthread_t *t = new pthread_t;
|
||||
pthread_create(t,NULL,working,this);
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
virtual void do_foo() {
|
||||
std::cout << "foo" << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%inline {
|
||||
extern "C" void* working(void* t) {
|
||||
Foo* f = static_cast<Foo*>(t);
|
||||
while (1) {
|
||||
sleep(1);
|
||||
std::cout << "invoked" << std::endl;
|
||||
f->do_foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/test-suite/python/director_thread_runme.py
Normal file
11
Examples/test-suite/python/director_thread_runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from director_thread import Foo
|
||||
|
||||
class Derived(Foo) :
|
||||
def __init__(self):
|
||||
Foo.__init__(self)
|
||||
print "too"
|
||||
def do_foo(self):
|
||||
print "at drived class"
|
||||
|
||||
d = Derived()
|
||||
d.run()
|
||||
Loading…
Add table
Add a link
Reference in a new issue