[thread]Is shared_mutex recursive with respect to shared locks?

In other words, should the following code result in a deadlock?
#include <iostream>
#include

AMDG Ken Savela wrote:
In other words, should the following code result in a deadlock?
#include <iostream>
#include
int main(int argc, char* argv[]) { boost::shared_mutex smx;
boost::upgrade_lockboost::shared_mutex lock_one(smx); std::cout << "Locked once." << std::endl; std::cout.flush(); boost::upgrade_lockboost::shared_mutex lock_two(smx); std::cout << "Locked again." << std::endl; std::cout.flush(); boost::upgrade_to_unique_lockboost::shared_mutex lock_three(lock_two); std::cout << "Write lock." << std::endl;
return 0; }
This example illustrates the problem I'm having in my app -- I have a situation where a single thread may end up performing more than a single shared lock. When it does so, it hangs on the nested upgrade_lock. Is this the expected behavior?
Yes this is the expected behavior. When you try to upgrade the second shared lock it blocks until the other shared_lock is released. i.e. never. In Christ, Steven Watanabe
participants (2)
-
Ken Savela
-
Steven Watanabe