C++0x has no semaphores? How to synchronize threads?

后端 未结 10 853
无人及你
无人及你 2020-11-22 07:18

Is it true that C++0x will come without semaphores? There are already some questions on Stack Overflow regarding the use of semaphores. I use them (posix semaphores) all the

10条回答
  •  花落未央
    2020-11-22 07:45

    C++20 will finally have semaphores - std::counting_semaphore.

    These will have (at least) the following methods:

    • acquire() (blocking)
    • try_acquire() (non-blocking, returns immediatel)
    • try_acquire_for() (non-blocking, takes a duration)
    • try_acquire_until() (non-blocking, takes a time at which to stop trying)
    • release()

    This isn't listed on cppreference yet, but you can read these CppCon 2019 presentation slides, or watch the video. There's also the official proposal P0514R4, but I'm not sure that's the most up-to-date version.

提交回复
热议问题