CSingleLock::Unlock

This method releases the synchronization object owned by CSingleLock. This method is called by the destructor for the CSingleLock class. If you need to release more than one access count of a semaphore, use the second implementation of Unlock and specify the number of accesses to release.

BOOL Unlock( ); 

BOOL Unlock(
LONG lCount,
LPLONG lPrevCount = NULL ); 

Parameters

  • lCount
    Specifies the number of accesses to release. Must be greater than 0. If the specified amount would cause the count of the object to exceed its maximum, the count is not changed and the function returns FALSE.
  • lPrevCount
    Points to a variable to receive the previous count of the synchronization object. If NULL, the previous count is not returned.

Return Value

Nonzero if the function was successful; otherwise, it is zero.

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

**  Windows CE versions:** 1.0 and later  
  Header file: Declared in Afxmt.h
  Platform: H/PC Pro, Palm-size PC, Pocket PC