Skip to content

Instantly share code, notes, and snippets.

@warmist
Created August 7, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmist/4061e26db94429d67dc3ca9e9a5141ca to your computer and use it in GitHub Desktop.
Save warmist/4061e26db94429d67dc3ca9e9a5141ca to your computer and use it in GitHub Desktop.
threading experiment
#include <mutex>
template<typename T,typename M=std::mutex>
struct protected_variable
{
T data;
M data_mutex;
template <typename F>
void with(F f){
std::lock_guard<M> lock(data_mutex);
f(data);
}
std::pair<std::lock_guard<M>,T&> get(){
return std::make_pair(std::lock_guard<M>(data_mutex),data);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment