Condividi tramite


CSingleLock::CSingleLock

Costruisce un oggetto CSingleLock.

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

Parametri

  • pObject
    Punti all'oggetto di sincronizzazione di accesso.Non è possibile NULL.

  • bInitialLock
    Specifica se inizialmente tentare di accedere all'oggetto fornito.

Note

Questa funzione è denominata nell'interno di una funzione membro della risorsa controllata.

Esempio

// 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();
}

Requisiti

Header: afxmt.h

Vedere anche

Riferimenti

Classe di CSingleLock

Grafico della gerarchia