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

后端 未结 10 1035
无人及你
无人及你 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条回答
  •  猫巷女王i
    2020-11-22 07:30

    in acordance with posix semaphores, I would add

    class semaphore
    {
        ...
        bool trywait()
        {
            boost::mutex::scoped_lock lock(mutex_);
            if(count_)
            {
                --count_;
                return true;
            }
            else
            {
                return false;
            }
        }
    };
    

    And I much prefer using a synchronisation mechanism at a convenient level of abstraction, rather than always copy pasting a stitched-together version using more basic operators.

提交回复
热议问题