-
Type:
Task
-
Resolution: Declined
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Server Programmability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The mongo::Atomic<T> is a wrapper around std::atomic<T>, but it does not expose the C++20 wait/notify API (wait(), notify_one(), notify_all()). These methods provide a futex-style blocking mechanism where a thread can block until the atomic's value changes, without spinning and without the overhead of a full mutex/condvar pair.
Proposed change:
Add the following three methods to atomic_detail::Base<T, Category::kBasic> (so all Atomic<T> specialisations inherit them):
void wait(T old) const noexcept; // blocks until value != old (seq_cst) void notify_one() noexcept; // unblocks one waiter void notify_all() noexcept; // unblocks all waiters
Follow the existing API convention, we should expose only the sequentially-consistent variant (no explicit memory_order parameter), consistent with how load(), store(), fetchAndAdd() etc. are all seq_cst by default. The wait call does not need a relaxed variant: the only meaningful orderings for a blocking operation are acquire and seq_cst, both of which are satisfied by the default seq_cst.