We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
pybind11::gil_safe_call_once_and_store
1 parent 87ec9af commit 7f01183Copy full SHA for 7f01183
pybind11_protobuf/proto_cast_util.cc
@@ -2,6 +2,7 @@
2
3
#include <Python.h>
4
#include <pybind11/cast.h>
5
+#include <pybind11/gil_safe_call_once.h>
6
#include <pybind11/pybind11.h>
7
#include <pybind11/pytypes.h>
8
@@ -150,8 +151,12 @@ class GlobalState {
150
151
// due to order of destruction conflict with python threads. See
152
// https://github.com/pybind/pybind11/issues/1598
153
static GlobalState* instance() {
- static auto instance = new GlobalState();
154
- return instance;
+ PYBIND11_CONSTINIT static pybind11::gil_safe_call_once_and_store<
155
+ GlobalState*>
156
+ storage;
157
+ return storage
158
+ .call_once_and_store_result([]() { return new GlobalState(); })
159
+ .get_stored();
160
}
161
162
py::handle global_pool() { return global_pool_; }
0 commit comments