Last active
August 29, 2015 14:05
-
-
Save dirvine/a7dfc4a1551c18fce5a2 to your computer and use it in GitHub Desktop.
monitor<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
class Atomic { | |
private: | |
mutable T t; | |
mutable std::mutex m; | |
public: | |
Atomic( T t_ ) : t( t_ ) { } | |
template<typename F> | |
auto operator()( F f ) const -> decltype(f(t)) | |
{ std::lock_guard<mutex> hold{m}; return f(t); } | |
}; | |
// C++ and Beyond 2012 | |
// herb sutter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment