CSingleLock lock(m_pMutex);
PMPEG1_PACK Result = NULL;
lock.Lock(1000);
if (lock.IsLocked())
{
if (!DataList.IsEmpty())
Result = DataList.RemoveHead();
lock.Unlock();
}
return Result;他使用CSingleLock 的作用是不是防止在RemoteHead 的时候有其他读写的操作?

解决方案 »

  1.   

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