jeudi 27 août 2015

Can thread trying to std::lock[_unique] an std::shared_mutex be starved by threads calling std::lock_shared?

A question regarding std::shared_mutex and the acquiring of unique_lock.

Assume there are 3 threads:

  • 2 readers (trying to lock_shared() the std::shared_mutex), and
  • 1 writer (trying to lock[_unique]() the std::shared_mutex)

Is it possible that the writer trying to lock[_unique]() would be starved? E.g.: at all times at least one reader owns a std::shared_lock, and lock[_unique]() can never succeed.

More or less: would lock[_unique]() on a std::shared_mutex block any attempts to further lock_shared() it?


(pretty sure boost::upgrade_lock could work here, but I'd like to know if there's any guarantee for bare std::unique_lock on a std::shared_mutex)

Aucun commentaire:

Enregistrer un commentaire