Untitled
Anonymous
c_cpp
01/29/2025 11:48 PM
660 B
25
Indexable
// 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
}Editor is loading...
Leave a Comment