开发者

how can I temporarily pause other threads using boost::thread?

I have a program with 2 threads (A and B). Is it possible to define a block of code in thread B, which once entered pauses thread A until the block has finished executing?

I am using C++ and the library boost::thread 1.44

开发者_如何学C

EDIT: The problem I had, which prevented me from just using a mutex was that I did not have access to the code in thread A as it's a non-thread-safe library, so I could not control when it accessed my shared resource. I have made some architectural changes to my code and now the resource is no longer shared and the problem is solved.


This is called locking and in boost you would want to use scoped_lock

Check this page out: scoped_lock


Other than the scoped_lock/mutex solution of Grammin you can use a condition variable (perhaps a more common idiom for your problem) or even a barrier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜