开发者

Is there a disadvantage to using boost::interprocess::interprocess_semaphore within a single multithreaded c++ process?

开发者 https://www.devze.com 2023-01-20 09:02 出处:网络
The disadvantage would be in comparison to a technique that was specialized to work on threads that are running within the same process. For example, does wait/post cause the whole process to yield, r

The disadvantage would be in comparison to a technique that was specialized to work on threads that are running within the same process. For example, does wait/post cause the whole process to yield, rather than just the executing thread, even though anyone waiting for a post would be within the same process?

The semaphore would be used, for example, to solve a producer/consumer problem in a shared buffer between two threads in the same process.

Are there any reasonable alternativ开发者_开发问答es?


Use Boost.Thread condition variables as shown here. The accompanying article has a good summary of Boost.Thread features.

Using interprocess semaphores will work but it's likely to place a tax on your execution due to use of unnecessarily heavyweight underlying OS locking primitives (named kernel objects in Windows, for example).

0

精彩评论

暂无评论...
验证码 换一张
取 消