File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,9 +125,10 @@ typedef struct {
125125 // This backend is only selected when the GIL is enabled, so this flag is a
126126 // plain int relying on the GIL for serialization: it is only ever touched
127127 // with the GIL held (the blocking sem_wait drops the GIL, but the flag
128- // store happens after the GIL is reacquired). CPython keeps the same flag
129- // as a plain `char` in its _thread lock wrapper (Modules/_threadmodule.c)
130- // for exactly this purpose.
128+ // store happens after the GIL is reacquired). This mirrors the old
129+ // PyThread_type_lock wrapper bookkeeping used by CPython 3.12 and earlier,
130+ // where _thread lock kept a plain `char locked` for sanity checks and
131+ // locked().
131132 int locked ;
132133} LockObject ;
133134
@@ -451,7 +452,8 @@ Lock_is_locked(LockObject *self)
451452 return result ;
452453#elif defined(LOCK_BACKEND_SEM )
453454 // The flag is GIL-serialized (see the struct comment); locked() is a
454- // plain read, matching CPython's _thread lock.
455+ // plain read, matching the old CPython _thread lock bookkeeping described
456+ // above.
455457 return self -> locked != 0 ;
456458#else // pthread mutex + condvar fallback
457459 // `locked` is only ever accessed under `mut`; take it for a clean read.
Original file line number Diff line number Diff line change 1313 dependencies = [LIBRT_THREADING ],
1414)
1515
16- # Lock.acquire() -- blocking acquire, always returns True
16+ # Lock.acquire() -- blocking acquire, returns True unless it raises
1717lock_acquire_op = method_op (
1818 name = "acquire" ,
1919 arg_types = [lock_rprimitive ],
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ def test_contention() -> None:
5454
5555def test_cross_thread_release() -> None:
5656 # threading.Lock is unowned: a lock acquired on one thread may be
57- # released from another. A thread blocked in acquire() must then wake up .
57+ # released from another, after which another thread can acquire it .
5858 import threading
5959 lock = Lock()
6060 assert lock.acquire()
@@ -71,7 +71,7 @@ def test_cross_thread_release() -> None:
7171 t = threading.Thread(target=releaser)
7272 t.start()
7373 started.wait()
74- # Blocks until releaser releases the lock on the other thread.
74+ # This may block until releaser releases the lock on the other thread.
7575 assert lock.acquire()
7676 t.join()
7777 assert released.is_set()
You can’t perform that action at this time.
0 commit comments