pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

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

Open beantowel opened this issue 1 year ago • 0 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [ ] Consider asking first in the Gitter chat room or in a Discussion.

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

beantowel avatar May 31 '24 02:05 beantowel