pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.08k stars 2.05k forks source link

[BUG]: acquire gil in new thread fails (access violation) #5152

Open beantowel opened 4 weeks ago

beantowel commented 4 weeks ago

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.12.0

Problem description

py::gil_scoped_acquire shall be ok to be used in cpp threads, but the example code would crush (access violation) when calling foo.test().

Reproducible example code

#include "pybind11/gil.h"
#include "pybind11/pybind11.h"
#include <stdio.h>
#include <thread>

namespace py = pybind11;

void test() {
    printf("acquire gil\n");
    py::gil_scoped_acquire acquire; // ok here
    std::thread([](){
        printf("acquire gil in new thread\n");
        py::gil_scoped_acquire acquire; // crush here
    }).join();
    printf("exit test\n");
}

PYBIND11_MODULE(foo, m) {
    m.def("test", &test);
}

Is this a regression? Put the last known working version here if it is.

Not a regression