Untitled
// so a simple raii use of mutex locking would be something like this: class MutexGuard { Mutex &mutex; public: MutexGuard(Mutex &mutex): mutex(mutex) { mutex.acquire(); } ~MutexGuard() { mutex.release(); } }; // which you can use like this: { MutexGuard guard(mutex); // upon construction this will automatically acquire the mutex for you // your code goes here.. // once this codeblock exits, guard will be deconstructed and automatically release the mutex for you }
Leave a Comment