Reputation: 53319
Consider this simple code:
boost::mutex m;
m.lock();
bool locked = m.try_lock();
std::cout<< (!locked? "Can't use lock" : "Can use lock.")<<std::endl;
system("pause");
The code print's Can't use lock
. This is a problem, because in my program, I need to perform an asynchronous operation only if the thread has exclusive rights to the lock. So:
Upvotes: 1
Views: 1415
Reputation: 62613
Your code is badly design. Any attempt to use a recursive mutex is an indication of a design bug. In your code, you need to protect the resource you need, and should not matter for you if your thread currently owns resource or not.
Upvotes: -2