MSDN:
If a thread calls LeaveCriticalSection when it does not have ownership of the specified critical section object, an error occurs that may cause another thread using EnterCriticalSection to wait indefinitely.
比如在MFC中使用
CCriticalSection m_MyCriticalSection; // 模块级变量
在某个函数中:
CSingleLock lock(&m_MyCriticalSection, TRUE);
//使用下面这行代码提前解除锁定,将会导致死锁,
//因为CSingleLock 的虚构函数还会调用一次m_MyCriticalSection.Unlock()
//m_MyCriticalSection.Unlock();
//要使用下面这行代码代替,因为这样CSingleLock 的虚构函数不会再调用m_MyCriticalSection.Unlock()
lock.Unlock();
	
posted on 2011-02-14 13:47 
张志松 阅读(4128) 
评论(0)  编辑 收藏 引用  所属分类: 
VC/MFC