Compartilhar via


CSingleLock::Unlock

Releases the synchronization object owned by CSingleLock.

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

Parameters

  • lCount
    Number of accesses to release. Must be greater than 0. If the specified amount would cause the object's count 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 0.

Remarks

This function is called by CSingleLock's destructor.

If you need to release more than one access count of a semaphore, use the second form of Unlock and specify the number of accesses to release.

Example

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

// Relate the synchronization object (m_Mutex) with
// our CSingleLock object. 
CSingleLock singleLock(&m_Mutex);

// Attempt to lock the shared resource
if (singleLock.Lock(100))    // Wait 100 ms...
{
    // We were able to lock the resource;
    // we may now work with the data associated with the mutex...

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

Requirements

Header: afxmt.h

See Also

Reference

CSingleLock Class

Hierarchy Chart