File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,6 @@ std::mutex thread_states_mutex;
3939//
4040// [1]: https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization
4141class PyGILGuard {
42- std::thread::id thread_id;
43-
4442 // The simplest way to implement this guard is to use `PyGILState_Ensure`
4543 // and `PyGILState_Release`, however this can lead to segfaults when
4644 // using libraries depending on pybind11.
@@ -78,18 +76,19 @@ class PyGILGuard {
7876
7977public:
8078 PyGILGuard () {
81- this -> thread_id = std::this_thread::get_id ();
79+ auto thread_id = std::this_thread::get_id ();
8280
8381 PyThreadStatePtr state;
8482
8583 {
8684 auto guard = std::lock_guard<std::mutex>(thread_states_mutex);
8785
88- if (thread_states.find (this -> thread_id ) == thread_states.end ()) {
86+ if (thread_states.find (thread_id) == thread_states.end ()) {
8987 // Note that PyThreadState_New does not require GIL to be held.
9088 state = PyThreadState_New (interpreter_state);
89+ thread_states[thread_id] = state;
9190 } else {
92- state = thread_states[this -> thread_id ];
91+ state = thread_states[thread_id];
9392 }
9493 }
9594
You can’t perform that action at this time.
0 commit comments