共用方式為


CSingleLock::CSingleLock

建構 CSingleLock 物件。

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

參數

  • pObject
    進行同步處理的物件存取。無法 NULL

  • bInitialLock
    指定是否一開始嘗試存取所提供的物件。

備註

這個函式通常會從控制資源的存取成員函式內。

範例

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

需求

Header: afxmt.h

請參閱

參考

CSingleLock 類別

階層架構圖