Skip to content

Remove dead prioritized-wait path from Unix WaitSubsystem#129081

Merged
jkotas merged 2 commits into
mainfrom
copilot/remove-prioritized-waits
Jun 7, 2026
Merged

Remove dead prioritized-wait path from Unix WaitSubsystem#129081
jkotas merged 2 commits into
mainfrom
copilot/remove-prioritized-waits

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

This change removes the unused prioritize wait path from Unix WaitSubsystem internals. All wait registration now follows the existing FIFO behavior, with no public API impact.

  • Entry-point cleanup (WaitSubsystem.Unix.cs)

    • Removed prioritize from internal Wait(...) and SignalAndWait(...) entry points.
    • Removed redundant prioritize: false forwarding at all internal call sites (NewMutex, CreateNamedMutex, single/multi-handle waits).
  • Interface and implementation signature alignment

    • Updated IWaitableObject.Wait_Locked(...) in WaitSubsystem.HandleManager.Unix.cs to remove prioritize.
    • Updated the IWaitableObject Wait(...) extension method to remove prioritize.
    • Updated implementations in:
      • WaitSubsystem.WaitableObject.Unix.cs
      • NamedMutex.Unix.cs
  • Wait registration simplification (WaitSubsystem.ThreadWaitInfo.Unix.cs)

    • Changed RegisterWait(int waitedCount, bool prioritize, bool isWaitForAll) to RegisterWait(int waitedCount, bool isWaitForAll).
    • Removed prioritized/LIFO branch and always register via FIFO RegisterWait(...).
    • Deleted WaitedListNode.RegisterPrioritizedWait(...).
  • Comment/reference consistency

    • Removed stale signature references tied to the old RegisterWait shape.
// Before
public void RegisterWait(int waitedCount, bool prioritize, bool isWaitForAll)
{
    if (prioritize)
        waitedListNodes[i].RegisterPrioritizedWait(waitedObjects[i]!);
    else
        waitedListNodes[i].RegisterWait(waitedObjects[i]!);
}

// After
public void RegisterWait(int waitedCount, bool isWaitForAll)
{
    waitedListNodes[i].RegisterWait(waitedObjects[i]!);
}
Original prompt

Goal

Remove all functionality related to prioritized waits in the Unix WaitSubsystem. The prioritize parameter exists on internal WaitSubsystem APIs but is effectively dead — every reachable call site passes prioritize: false (or uses an overload that hard‑codes it). Remove the parameter, the supporting plumbing, and the prioritized‑wait code path so the wait subsystem only supports fair (FIFO) waits.

Background

WaitSubsystem is the managed Unix implementation of WaitHandle/EventWaitHandle/Semaphore/Mutex. It is located under:

  • src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.Unix.cs
  • src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.HandleManager.Unix.cs
  • src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.ThreadWaitInfo.Unix.cs
  • src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.WaitableObject.Unix.cs
  • src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs (also defines an IWaitableObject implementation with Wait_Locked)

A prioritize boolean is plumbed through these APIs. When true, ThreadWaitInfo.RegisterWait calls WaitedListNode.RegisterPrioritizedWait instead of RegisterWait, which inserts the waiter at the head of the waiters list (LIFO) instead of the tail (FIFO). No caller in the repo ever passes prioritize: true — see analysis below.

Concrete changes

1. WaitSubsystem.Unix.cs

Remove the prioritize parameter from the two public entry points and their forwarders:

  • public static int Wait(IWaitableObject waitableObject, int timeoutMilliseconds, bool interruptible = true, bool prioritize = false) — drop prioritize parameter; update body to no longer pass it.
  • public static int SignalAndWait(IWaitableObject waitableObjectToSignal, IWaitableObject waitableObjectToWaitOn, int timeoutMilliseconds, bool interruptible = true, bool prioritize = false) — drop prioritize; update body to no longer pass it to Wait_Locked.

Also remove the now‑redundant prioritize: false named arguments at all internal call sites in this file (NewMutex, CreateNamedMutex, the Wait(ReadOnlySpan<IntPtr>, …) overload calls to WaitableObject.Wait and namedMutex.Wait, etc.).

2. WaitSubsystem.HandleManager.Unix.cs

  • In interface IWaitableObject, remove prioritize from Wait_Locked's signature:
    • From: int Wait_Locked(ThreadWaitInfo waitInfo, int timeoutMilliseconds, bool interruptible, bool prioritize, ref LockHolder lockHolder);
    • To: int Wait_Locked(ThreadWaitInfo waitInfo, int timeoutMilliseconds, bool interruptible, ref LockHolder lockHolder);
  • In the Wait extension method on IWaitableObject, drop the prioritize parameter and stop forwarding it.

3. WaitSubsystem.WaitableObject.Unix.cs

  • Remove prioritize from the signatures of both WaitableObject.Wait_Locked(...) and the static WaitableObject.Wait(WaitableObject?[]? waitableObjects, int count, bool waitForAll, ThreadWaitInfo waitInfo, int timeoutMilliseconds, bool interruptible, bool prioritize).
  • Update the internal call to waitInfo.RegisterWait(...) accordingly (see WIP: Initial CoreCLR CI pipeline in the composite repo #4).

4. WaitSubsystem.ThreadWaitInfo.Unix.cs

  • Change public void RegisterWait(int waitedCount, bool prioritize, bool isWaitForAll) to public void RegisterWait(int waitedCount, bool isWaitForAll).
  • In its body, remove the if (prioritize) { … RegisterPrioritizedWait(…) } else { … RegisterWait(…) } branch — always call the FIFO RegisterWait path.
  • Remove the WaitedListNode.RegisterPrioritizedWait(WaitableObject waitableObject) method entirely.

5. NamedMutex.Unix.cs

  • Update the NamedMutex.Wait_Locked method signature to match the new IWaitableObject interface (drop prioritize). The method body already ignores the parameter.

6. Eliminate all uses of prioritize named/positional arguments throughout the affected files

After the signature changes, fix up call sites and named arguments such as prioritize: false so things compile cleanly. The repo currently has no prioritize: true call sites.

7. Adjust the design-doc comments in WaitSubsystem.Unix.cs

The big doc comment at the top of WaitSubsystem.Unix.cs describes the design goals, including wait release fairness. No content changes are needed there since we're keeping the FIFO behavior, but please verify no comment in the affected files still references "prioritized" waits / RegisterPrioritizedWait / the prioritize parameter. Update or remove any such stale comments.

Reference: current call sites of the affected entry points

These are the only callers in the repo, and none pass prioritize: true:

  • WaitHandle.Unix.csWaitOneCore, WaitMultipleIgnoringSyncContextCore, SignalAndWaitCore use overloads without prioritize (Wait(IntPtr, int, bool), Wait(ReadOnlySpan<IntPtr>, bool, int), SignalAndWait(IntPtr, IntPtr, int)). These do not n...

This pull request was created from Copilot chat.

Copilot AI requested review from Copilot and removed request for Copilot June 6, 2026 21:00
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 6, 2026
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 6, 2026 21:33
Copilot AI changed the title [WIP] Remove functionality related to prioritized waits in WaitSubsystem Remove dead prioritized-wait path from Unix WaitSubsystem Jun 6, 2026
Copilot finished work on behalf of VSadov June 6, 2026 21:34
Copilot AI requested a review from VSadov June 6, 2026 21:34
@VSadov VSadov added area-System.Threading and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 6, 2026
@VSadov VSadov added this to the 11.0.0 milestone Jun 6, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

@VSadov VSadov marked this pull request as ready for review June 6, 2026 23:09
Copilot AI review requested due to automatic review settings June 6, 2026 23:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies the Unix WaitSubsystem internals in System.Private.CoreLib by removing the unused “prioritized wait” plumbing (prioritize parameter and the LIFO registration path). Wait registration now consistently uses the existing FIFO waiter-list behavior, with no new public surface area.

Changes:

  • Removed the prioritize parameter from internal wait entry points (Wait, SignalAndWait), IWaitableObject.Wait_Locked, and related helpers/implementations.
  • Simplified wait registration by removing the prioritized/LIFO branch and deleting RegisterPrioritizedWait, always registering waiters via FIFO RegisterWait.
  • Updated in-code references/comments to match the new RegisterWait(int, bool) signature.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.Unix.cs Removes prioritize from internal wait entry points and updates call sites/forwarding.
src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.HandleManager.Unix.cs Aligns IWaitableObject.Wait_Locked and the Wait extension method with the new signature.
src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.WaitableObject.Unix.cs Drops prioritize from wait implementations and updates RegisterWait call sites.
src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.ThreadWaitInfo.Unix.cs Removes the prioritized/LIFO registration path and deletes RegisterPrioritizedWait.
src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs Updates the NamedMutex Wait_Locked implementation signature to match the interface.

@VSadov VSadov requested a review from jkotas June 7, 2026 02:28
@jkotas jkotas merged commit 252fdb0 into main Jun 7, 2026
167 checks passed
@jkotas jkotas deleted the copilot/remove-prioritized-waits branch June 7, 2026 02:44
@VSadov
Copy link
Copy Markdown
Member

VSadov commented Jun 7, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants