Suppose we have the following (pseudo) code:
using UpgradeLock = boost::upgrade_lock<boost::shared_mutex>;
using UpgradeToUniqueLock = boost::upgrade_to_unique_lock<boost::shared_mutex>;
boost::shared_mutex mtx;
void DeleteTable(<tbl>) {
UpgradeLock lock(mtx);
if (<the table exists>) {
UpgradeToUniqueLock up(lock); // (!)
// delete the table
}
}
And suppose two threads have just entered into this function and both reached the statement, marked with (!)
.
I can't figure out what will happen then. I have the following options:
- One thread cannot acquire exclusive access until the second one releases its
UpgradeLock
, but it cannot until it gets exclusive access too. Deadlock. - One thread acquires exclusive access, while another one is being suspended at the line with mark
(!)
.
I guess the second option is what probably will happen, but in this case it comes out, that even having locked environment, we have to recheck that our data hasn't been changed "outside", i.e. we have to use the notorious DCLP. Am I right?
I haven't found any plausible info about it, so don't blame me a lot :)