[all-commits] [llvm/llvm-project] c36815: [libc][rwlock] fix timeout writer signal stealing ...

Schrodinger ZHU Yifan via All-commits all-commits at lists.llvm.org
Wed Jun 10 11:51:07 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c36815b3e2c42b70923ef6509532640c940dc00d
      https://github.com/llvm/llvm-project/commit/c36815b3e2c42b70923ef6509532640c940dc00d
  Author: Schrodinger ZHU Yifan <yfzhu at google.com>
  Date:   2026-06-10 (Wed, 10 Jun 2026)

  Changed paths:
    M libc/src/__support/threads/raw_rwlock.h

  Log Message:
  -----------
  [libc][rwlock] fix timeout writer signal stealing problem (#201937)

When a timeout triggers, the waiting thread wakes up, unregisters
itself from the waiting queue, and exits. However, if the timing-out
thread is preempted after waking up but before it can unregister,
and a concurrent unlock occurs during this window, the timing-out
thread may consume the wake-up signal.

For example, assume the lock is in writer-preference mode and a
writer (W0) holds the lock. A reader (R) and another writer (W1,
with a short timeout) arrive and join the queue. W1's timeout
expires, so it wakes up and attempts to acquire the queue lock,
but is preempted before succeeding. W0 then releases the lock and,
preferring writers, sends a wake-up signal to W1. When W1 resumes,
it acquires the queue lock, unregisters, and exits due to the
timeout, ignoring the wake-up signal. As a result, the reader (R)
is left waiting indefinitely, leading to a deadlock.

To fix this, we track whether the serialization number changed
specifically for writers, and propagate the wake signal if it did.
If the timing-out thread is a reader, signal consumption is safe
because:
1. If there are pending writers, they will be woken up first.
2. Otherwise, if there are pending readers, they are all woken up
   via broadcasting (notify_all), so one reader timing out does not
   steal others' signal.

Assisted-by: AI tools, manually checked



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list