mirror of
https://github.com/pybind/pybind11.git
synced 2026-07-16 16:48:07 +00:00
@@ -10,6 +10,7 @@
|
||||
#include "pybind11_tests.h"
|
||||
#include "constructor_stats.h"
|
||||
#include <pybind11/functional.h>
|
||||
#include <thread>
|
||||
|
||||
/* This is an example class that we'll want to be able to extend from Python */
|
||||
class ExampleVirt {
|
||||
@@ -157,6 +158,28 @@ struct DispatchIssue : Base {
|
||||
}
|
||||
};
|
||||
|
||||
static void test_gil() {
|
||||
{
|
||||
py::gil_scoped_acquire lock;
|
||||
py::print("1st lock acquired");
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
py::gil_scoped_acquire lock;
|
||||
py::print("2nd lock acquired");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void test_gil_from_thread() {
|
||||
py::gil_scoped_release release;
|
||||
|
||||
std::thread t(test_gil);
|
||||
t.join();
|
||||
}
|
||||
|
||||
|
||||
// Forward declaration (so that we can put the main tests here; the inherited virtual approaches are
|
||||
// rather long).
|
||||
void initialize_inherited_virtuals(py::module &m);
|
||||
@@ -414,7 +437,6 @@ public:
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
void initialize_inherited_virtuals(py::module &m) {
|
||||
// test_inherited_virtuals
|
||||
|
||||
@@ -447,4 +469,8 @@ void initialize_inherited_virtuals(py::module &m) {
|
||||
py::class_<D_Tpl, C_Tpl, PyB_Tpl<D_Tpl>>(m, "D_Tpl")
|
||||
.def(py::init<>());
|
||||
|
||||
|
||||
// Fix issue #1454 (crash when acquiring/releasing GIL on another thread in Python 2.7)
|
||||
m.def("test_gil", &test_gil);
|
||||
m.def("test_gil_from_thread", &test_gil_from_thread);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user