The C++20 std::counting_semaphore is a synchronization primitive that can limit the number of concurrent threads accessing a shared resource.
The typical use cases overlap with std::condition_variable; however, std::counting_semaphore offers a more straightforward interface and potentially better performance.
Compiler Explorer link: https://compiler-explorer.com/z/9daM1xaT3