4 ms·
I prefer to use language constructs to enforce correct usage where possible. For example, if a set of values have to be synchronized by a mutex, I wrap them in
by zvrba 10y ago
I prefer to use language constructs to enforce correct usage where possible.
For example, if a set of values have to be synchronized by a mutex, I wrap them in a struct and http://www.boost.org/doc/libs/1_63_0/doc/html/thread/sds.html#thread.sds.synchronized_valuesxxx http://www.boost.org/doc/libs/1_63_0/doc/html/thread/sds.htm...
If a method requires that it's called while a mutex is held, I make it explicit by declaring the function as `void f(std::unique_lock<std::mutex>&)` [requiring a reference ensures that you have to have a constructed object before function entry]. Granted, this approach doesn't associate the mutex with its data.