Skip to content

Commit 5e62d5b

Browse files
committed
Update comments
1 parent ba18b68 commit 5e62d5b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Modules/_testinternalcapi/test_critical_sections.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ thread_stw(void *arg)
405405
}
406406

407407
// All threads: acquire critical section and hold it long enough to
408-
// trigger TIME_TO_BE_FAIR_NS, which causes direct handoff on unlock.
408+
// trigger TIME_TO_BE_FAIR_NS (1 ms), which causes direct handoff on unlock.
409409
Py_BEGIN_CRITICAL_SECTION(test_data->obj);
410-
pysleep(10);
410+
pysleep(10); // 10 ms = 10 x TIME_TO_BE_FAIR_NS
411411
Py_END_CRITICAL_SECTION();
412412

413413
PyGILState_Release(gil);

Python/critical_section.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ _PyCriticalSection_BeginSlow(PyThreadState *tstate, PyCriticalSection *c, PyMute
4545
}
4646
// If the world is stopped, we don't need to acquire the lock because
4747
// there are no other threads that could be accessing the object.
48+
// Without this check, acquiring a critical section while the world is
49+
// stopped could lead to a deadlock.
4850
if (tstate->interp->stoptheworld.world_stopped) {
4951
c->_cs_mutex = NULL;
5052
c->_cs_prev = 0;

0 commit comments

Comments
 (0)