Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
C++ and Beyond 2012: Herb Sutter - C++ Concurrency
Jan 13, 2013 at 7:19 AMThis session is really cool, many thanks.
Anyway I am a little bit confused about monitor<T>.
I could understand why std::mutex is mutable (I mean thread safe under C++11).
But why T is mutable?
The all public interfaces of std::mutex would provide thread safe but what about T?
I guess only const member functions would provide thread safe.
Should mutable be a qualifier for that instance of std:mutex or the std:mutex class itself (C++1y)?
Could mutable be a qualifier for a member function such as const (C++1y)?
Which one is better?
1. template <typename F> auto operator()(F f) const
2. template <typename F> auto operator()(F f) mutable
If const member T functions would provide thread safe, why bother to operate under std::lock_guard<mutex>?
I know monitor<T> would be easier to provide a general solution under a thread safe way.
But I might use a dangerous way like below for some critical cases (it might be very few)
template <class T> class monitor : public T {
private:
mutable std::mutex m;
public:
monitor(T t_ = T{}) : T(t_) {}
template <typename F> auto operator()(F f) ...
};
I might call some const member T functions directly for precondition checking whether I need to go for operator() under critical cases.