class Mutex : private NoCopy
This well know synchronization primitive is usually used to serialize access to shared data or other shared resources. Only single thread can execute the code between calls to Enter and Leave. If any other thread attempts to Enter the protected section while other thread is performing it, it is blocked until performing thread indicates leaving the section by invoking Leave. Mutex is reentrant (same thread can Enter the Mutex multiple times).
Enter the protected region of code. Only single thread can enter the region, other threads block until Leave is invoked.
Attempts to enter the protected region of code. If other thread owns the region, returns false, otherwise gains the ownership of Mutex and returns true. Never blocks.
Leave the protected region of code. Only the same thread that called Enter can invoke Leave.
Variant of Mutex that can be used as static or global variable without the need of initialization - it has no constructor and correctly performs the first initialization when any of methods is called. That avoids problems with initialization order or multithreaded initialization issues.
Returns the initialized instance of Mutex.
Calls respective methods of Mutex instance.
This nested class automates calls to Mutex::Enter / Mutex::Leave for block of code using C++ constructor / destructor rules. Using operator StaticMutex::Mutex, it can be used with StaticMutex as well.
Constructor / Destructor detail
Performs s.Enter() where s is the constructor parameter.