if this is a bug I have no problem just not doing it, but if this is an expected behaviour I would like to know why.
I do something like this:
{
boost::lock_guard<boost::mutex> lg(tagsToSocketsMtx);
// mutex protected work
lg.~lock_guard(); // this causes deadlocks later(combined with ...
//...other uses of the same mtx, ofc I use different lock guard in other functions)
// rest of the function
}
Once the construction of
lgcompletes, C++ guarantees that its destructor will be called on scope exit regardless of the fact that you’re are also making an explicit destructor call.By destroying
lgtwice, you are invoking undefined behaviour, and in this case the bug manifests as a deadlock.