Skip to content

Instantly share code, notes, and snippets.

@lucindo
Created November 22, 2010 19:52
Show Gist options
  • Save lucindo/710543 to your computer and use it in GitHub Desktop.
Save lucindo/710543 to your computer and use it in GitHub Desktop.
class MutexGuard
{
private:
Mutex & mutex_;
public:
MutexGuard(Mutex & mutex) : mutex_(mutex)
{
mutex_.aquire();
}
~MutexGuard()
{
mutex_.release();
}
};
(...)
void concurrent_operation()
{
(....);
MutexGuard guard(my_mutex);
// only one thread here...
(...);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment