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

后端 未结 10 838
无人及你
无人及你 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:51

    You can work with mutex and condition variables. You gain exclusive access with the mutex, check whether you want to continue or need to wait for the other end. If you need to wait, you wait in a condition. When the other thread determines that you can continue, it signals the condition.

    There is a short example in the boost::thread library that you can most probably just copy (the C++0x and boost thread libs are very similar).

提交回复
热议问题