CSingleLock::Lock

调用此函数同步对象控件的资源访问提供给 CSingleLock 构造函数。

BOOL Lock(
   DWORD dwTimeOut = INFINITE 
);

参数

  • dwTimeOut
    指定时间等待同步对象可用(终止)。 如果 INFINITE,Lock 将等待,直到对象在返回之前终止状态。

返回值

非零,如果函数运行成功;否则为0。

备注

如果同步对象收到信号,Lock 将成功返回,并且该线程现在拥有对象。 如果同步对象nonsignaled (不可用),Lock 将等待同步对象变为终止状态到在 dwTimeOut 参数指定的毫秒数。 如果同步对象在指定的时间不会变为终止状态,Lock 返回失败。

示例

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

要求

Header: afxmt.h

请参见

参考

CSingleLock选件类

层次结构图