Freigeben über


CSingleLock Class

Represents the access-control mechanism used in controlling access to a resource in a multithreaded program.

class CSingleLock

Remarks

CSingleLock does not have a base class.

In order to use the synchronization classes CSemaphore, CMutex, CCriticalSection, and CEvent, you must create either a CSingleLock or CMultiLock object to wait on and release the synchronization object. Use CSingleLock when you only need to wait on one object at a time. Use CMultiLock when there are multiple objects that you could use at a particular time.

To use a CSingleLock object, call its constructor inside a member function in the controlled resource's class. Then call the IsLocked member function to determine if the resource is available. If it is, continue with the remainder of the member function. If the resource is unavailable, either wait for a specified amount of time for the resource to be released, or return failure. After use of the resource is complete, either call the Unlock function if the CSingleLock object is to be used again, or allow the CSingleLock object to be destroyed.

CSingleLock objects require the presence of an object derived from CSyncObject. This is usually a data member of the controlled resource's class. For more information on how to use CSingleLock objects, see the article Multithreading: How to Use the Synchronization Classes.

Requirements

Header: afxmt.h

See Also

Concepts

CSingleLock Members

Hierarchy Chart

CMultiLock Class