[libc-commits] [libc] [libc][rwlock] fix timeout writer signal stealing problem (PR #201937)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Wed Jun 10 01:18:40 PDT 2026


================
@@ -405,22 +405,55 @@ class RawRwLock {
       }
 
       // Phase 7: unregister ourselves as a pending reader/writer.
+      bool writer_serial_changed = false;
       {
         // Similarly, the unregister operation should also be an atomic
         // transaction.
         WaitingQueue::Guard guard = queue.acquire(is_pshared);
         guard.pending_count<role>()--;
-        // Clear the flag if we are the last reader. The flag must be
+        // Clear the flag if we are the last one. The flag must be
         // cleared otherwise operations like trylock may fail even though
         // there is no competitors.
         if (guard.pending_count<role>() == 0)
           RwState::fetch_clear_pending_bit<role>(state,
                                                  cpp::MemoryOrder::RELAXED);
+        if constexpr (role == Role::Writer) {
+          int new_serial =
----------------
labath wrote:

I see `serial_number` is already an int, but it may be worth changing both to `FutexWordType`. I found the use of `int` for a serial number surprising, and it got me thinking about scenarios like the serial number overflowing (UB) and the like...

https://github.com/llvm/llvm-project/pull/201937


More information about the libc-commits mailing list