Share via


CSingleLock::CSingleLock

Crea un objeto CSingleLock.

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

Parámetros

  • pObject
    Señala al objeto de sincronización se alcance.no puede ser NULL.

  • bInitialLock
    Especifica si intentar inicialmente tener acceso al objeto proporcionado.

Comentarios

Esta función se denomina normalmente dentro de una función miembro de acceso al recurso controlado.

Ejemplo

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

Requisitos

encabezado: afxmt.h

Vea también

Referencia

Clase CSingleLock

Gráfico de jerarquía