File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -627,15 +627,23 @@ TEST_CASE("Threads") {
627627
628628 {
629629 py::gil_scoped_release gil_release{};
630+ #if defined(Py_GIL_DISABLED) && PY_VERSION_HEX < 0x030E0000
631+ std::mutex mutex;
632+ #endif
630633
631634 auto threads = std::vector<std::thread>();
632635 for (auto i = 0 ; i < num_threads; ++i) {
633636 threads.emplace_back ([&]() {
634637 py::gil_scoped_acquire gil{};
635638#ifdef Py_GIL_DISABLED
639+ # if PY_VERSION_HEX < 0x030E0000
640+ std::lock_guard<std::mutex> lock (mutex);
641+ locals[" count" ] = locals[" count" ].cast <int >() + 1 ;
642+ # else
636643 Py_BEGIN_CRITICAL_SECTION (locals.ptr ());
637644 locals[" count" ] = locals[" count" ].cast <int >() + 1 ;
638645 Py_END_CRITICAL_SECTION ();
646+ # endif
639647#else
640648 locals[" count" ] = locals[" count" ].cast <int >() + 1 ;
641649#endif
You can’t perform that action at this time.
0 commit comments