Skip to content

Instantly share code, notes, and snippets.

@dirvine
Last active August 29, 2015 14:05
Show Gist options
  • Save dirvine/a7dfc4a1551c18fce5a2 to your computer and use it in GitHub Desktop.
Save dirvine/a7dfc4a1551c18fce5a2 to your computer and use it in GitHub Desktop.
monitor<T>
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