Note that the vector must sometimes be searched again. This is necessary because upgrade_to_writer might have to temporarily release the lock before it can upgrade. Otherwise, deadlock might ensue, as discussed in Lock Pathologies. Method upgrade_to_writer returns a bool that is true if it successfully upgraded the lock without releasing it, and false if the lock was released temporarily. Thus when upgrade_to_writer returns false, the code must rerun the search to check that the key was not inserted by another writer. The example presumes that keys are always added to the end of the vector, and that keys are never removed. Because of these assumptions, it does not have to re-search the entire vector, but only the elements beyond those originally searched. The key point to remember is that when upgrade_to_writer returns false, any assumptions established while holding a reader lock may have been invalidated, and must be rechecked.

For symmetry, there is a corresponding method downgrade_to_reader, though in practice there are few reasons to use it.