Skip to content

Commit 7e753f1

Browse files
committed
Add missing assignment
1 parent 9e31fa2 commit 7e753f1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

c_src/pythonx/pythonx.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ std::mutex thread_states_mutex;
3939
//
4040
// [1]: https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization
4141
class 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

7977
public:
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

0 commit comments

Comments
 (0)