Dela via


CSingleLock::CSingleLock

Constructs a CSingleLock object.

explicit CSingleLock(
   CSyncObject* pObject,
   BOOL bInitialLock = FALSE 
);

Parameters

  • pObject
    Points to the synchronization object to be accessed. Cannot be NULL.

  • bInitialLock
    Specifies whether to initially attempt to access the supplied object.

Remarks

This function is generally called from within an access member function of the controlled resource.

Example

// m_CritSection is a data member (of type CCriticalSection)
// of an existing class that implements the resource being shared.

// Relate the synchronization object (m_CritSection) with
// our CSingleLock object. 
CSingleLock singleLock(&m_CritSection);
singleLock.Lock();  // Attempt to lock the shared resource
if (singleLock.IsLocked())  // Resource has been locked
{
   //...use the shared resource...

   // Now that we are finished, 
   // unlock the resource for others.
   singleLock.Unlock();
}

Requirements

Header: afxmt.h

See Also

Reference

CSingleLock Class

Hierarchy Chart

Other Resources

CSingleLock Members