Use `NtAssociateWaitCompletionPacket` to register wait handle callbacks on Windows.
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Since Windows 8, the Windows thread pool has been able to [serve an unbounded number of wait callbacks with a single thread](https://devblogs.microsoft.com/oldnewthing/20220406-00/?p=106434), by using the [`NtAssociateWaitCompletionPacket`](https://learn.microsoft.com/en-us/windows/win32/devnotes/ntassociatewaitcompletionpacket) API to register wait handle completion packets on an I/O completion port. We can make use of this API in the portable thread pool, by leveraging its existing I/O completion port. Other environments like [Go](https://go.dev/src/runtime/netpoll_windows.go) and [Bun](https://github.com/oven-sh/libuv/commit/96873308d4505884ba4f82ac89905fe0fd97eb9e) are using it too.
If it's OK to do, should we keep the existing `PortableThreadPool.WaitThread` mechanism as a fallback if `NtAssociateWaitCompletionPacket` does not exist? It should exist on all Windows versions currently supported by .NET, barring potential outliers like Xbox.
Contributor guide
Assessment
This issue has not been assessed yet.