-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Service Arch
-
Fully Compatible
-
Service Arch 2023-12-11, Service Arch 2023-12-25, Service Arch 2024-01-08, Service Arch 2024-01-22, Service Arch 2024-02-05, Service Arch 2024-02-19
In a few places we've either wanted to use C++20's std::atomic::wait() and notify apis, or have code currently using a mutex+condvar+enum/bool that could be using that instead. Unfortunately, the sandardized APIs don't support timeouts or deadlines (due to issues around freestanding support) while effectively all of our usages need them. Luckily, all of the OSes we support provide APIs that do take timeouts or deadlines, so we should just build our own wait/notify abstraction on top of them. We can use the try_wait_for and try_wait_until APIs proposed here. We can base it on the implementation in libc++ (covering linux, apple/darwin, and freebsd) and use WaitOnAddress / WakeByAddressSingle / WakeByAddressAll on windows (the MSSTL implementation is convoluted to support old windows versions without those APIs, but we dont need to support them).
I think it would be best to add a new AtomicWaitable<T> type that publicly derives from AtomicWord<T> but ensures that `T` is a size that is supported natively by the current platform (all platforms seem to support 32bit words, so we could just require that everywhere). We could also consider adding a fallback implementation that adds a mutex+condvar to the subclass and uses them for notifications. If sizeof(T) is smaller than the platform natively supports (eg bool on linux) we could consider padding it out and using an underlying AtomicWaitable<uint32_t> rather than failing to compile and requiring the caller to do their own padding.
- fixes
-
SERVER-85781 Remove duplicate definitions of JoinThread class for testing
- Closed
- is depended on by
-
SERVER-86461 Implement a ticket holder based on AtomicWaitable
- Closed
-
SERVER-72616 Remove futex usage in favour of std::atomic/AtomicWord::wait on TicketPool
- Closed
-
SERVER-83053 Use atomic wait/notify in AsioNetworkingBaton instead of ::poll when there are no sessions
- Closed
- is duplicated by
-
SERVER-72064 Implement AtomicWord::wait similar to std::atomic::wait
- Closed
- is related to
-
SERVER-86362 Move platform based code in separate .cpp files for AtomicWaitable and use respective OS primitives.
- Closed
-
WT-11836 Use futexes when waiting for a resource
- Blocked
-
SERVER-72064 Implement AtomicWord::wait similar to std::atomic::wait
- Closed
- related to
-
SERVER-81793 Don't do any syscalls to notify a baton that isn't in poll
- Closed