Skip to content

Instantly share code, notes, and snippets.

@cyfdecyf
Created September 11, 2018 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyfdecyf/e33fd41c2ee4395d2bb98c4e23e59648 to your computer and use it in GitHub Desktop.
Save cyfdecyf/e33fd41c2ee4395d2bb98c4e23e59648 to your computer and use it in GitHub Desktop.
pybind11 TLS test
cmake_minimum_required (VERSION 2.8)
add_subdirectory(pybind11)
pybind11_add_module(test_gil test_gil.cc)
import test_gil
test_gil.test()
test_gil.test_in_new_thread()
#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