Created
May 17, 2019 23:29
-
-
Save lega911/4f3887c73e6d41ec3ca74dfbc069e421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
from ctypes import cdll | |
lib = cdll.LoadLibrary('./liblib.so') | |
class Foo(object): | |
def __init__(self): | |
self.obj = lib.Foo_new() | |
def bar(self): | |
lib.Foo_bar(self.obj) | |
def run(): | |
f = Foo() | |
f.bar() | |
threading.Thread(target=run).start() | |
threading.Thread(target=run).start() | |
threading.Thread(target=run).start() | |
p = threading.Thread(target=run) | |
p.start() | |
p.join() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ -c -fPIC lib.cpp -o lib.o | |
// g++ -shared -Wl,-soname,liblib.so -o liblib.so lib.o | |
#include <iostream> | |
class Foo{ | |
public: | |
void bar(){ | |
std::cout << "Start" << std::endl; | |
for(int i=0;i<100000000;i++) { | |
for(int j=0;j<100000000;j++) {} | |
} | |
std::cout << "End" << std::endl; | |
} | |
}; | |
extern "C" { | |
Foo* Foo_new(){ return new Foo(); } | |
void Foo_bar(Foo* foo){ foo->bar(); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment