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
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.
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.