Skip to content

Commit 556b06f

Browse files
committed
Update some comments
1 parent f6901bb commit 556b06f

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

mypyc/lib-rt/threading/librt_threading.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff 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.

mypyc/primitives/librt_threading_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
dependencies=[LIBRT_THREADING],
1414
)
1515

16-
# Lock.acquire() -- blocking acquire, always returns True
16+
# Lock.acquire() -- blocking acquire, returns True unless it raises
1717
lock_acquire_op = method_op(
1818
name="acquire",
1919
arg_types=[lock_rprimitive],

mypyc/test-data/run-threading.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_contention() -> None:
5454

5555
def 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()

0 commit comments

Comments
 (0)