Created
September 11, 2018 06:18
-
-
Save cyfdecyf/e33fd41c2ee4395d2bb98c4e23e59648 to your computer and use it in GitHub Desktop.
pybind11 TLS test
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
cmake_minimum_required (VERSION 2.8) | |
add_subdirectory(pybind11) | |
pybind11_add_module(test_gil test_gil.cc) |
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 test_gil | |
test_gil.test() | |
test_gil.test_in_new_thread() |
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
#include <iostream> | |
#include <thread> | |
#include <pybind11/pybind11.h> | |
namespace py = pybind11; | |
static void test() { | |
{ | |
std::cerr << "1st lock\n"; | |
py::gil_scoped_acquire lock; | |
} | |
{ | |
std::cerr << "2nd lock\n"; | |
py::gil_scoped_acquire lock; | |
} | |
std::cerr << "test done\n"; | |
} | |
static void test_in_new_thread() { | |
py::gil_scoped_release release; | |
std::thread t(test); | |
t.join(); | |
} | |
PYBIND11_MODULE(test_gil, m) { | |
m.def("test", &test); | |
m.def("test_in_new_thread", &test_in_new_thread); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment