Initializes a mutex object.
Initializes a mutex object and sets it as the monitor for o.
A destructor is present on this object, but not explicitly documented in the source.
If this lock is not already held by the caller, the lock is acquired, then the internal counter is incremented by one.
If the lock is held by another caller, the method returns. Otherwise, the lock is acquired if it is not already held, and then the internal counter is incremented by one.
Decrements the internal lock count by one. If this brings the count to zero, the lock is released.
/////////////////////////////////////////////////////////////////////////////
1 auto mutex = new Mutex; 2 int numThreads = 10; 3 int numTries = 1000; 4 int lockCount = 0; 5 6 void testFn() 7 { 8 for( int i = 0; i < numTries; ++i ) 9 { 10 synchronized( mutex ) 11 { 12 ++lockCount; 13 } 14 } 15 } 16 17 auto group = new ThreadGroup; 18 19 for( int i = 0; i < numThreads; ++i ) 20 group.create( &testFn ); 21 22 group.joinAll(); 23 assert( lockCount == numThreads * numTries );
This class represents a general purpose, recursive mutex.