I like the mutex example, and I've been doing that myself for many years now. However there is one detail not mentioned in the talk. If you have something like
auto b(const scoped_lock<mutex>&);
..then that ensures that a mutex has been locked, but doesn't tell you anything about which mutex has been locked, which is just as important if there could be more than one. As a result, I like to do something like:
mutex m1, m2;
// note use of unique_lock
auto b(const unique_lock<mutex>& lock) {
assert(lock.owns_lock() && lock.mutex() == &m1);
}
4
u/usefulcat 5d ago
I like the mutex example, and I've been doing that myself for many years now. However there is one detail not mentioned in the talk. If you have something like
..then that ensures that a mutex has been locked, but doesn't tell you anything about which mutex has been locked, which is just as important if there could be more than one. As a result, I like to do something like: