我是一名支持工程师,在一个失败进程的转储中,我看到有一些锁。
ClassName::F()
)回来了。该函数使用关键部分并调用子函数(
ClassName::f_sub()
),他在说同样的关键部分,简而言之:
int ClassName::f_sub(){
EnterCriticalSection(&m_cs);
...
LeaveCriticalSection(&m_cs);
return ...;
}
int ClassName::F() {
EnterCriticalSection(&m_cs);
...
int temp = f_sub();
...
LeaveCriticalSection(&m_cs);
return ...;
}
每次都是同样的关键部分
m_cs
(财产
ClassName
在我看来,这使得以下顺序成为可能:
Thread 1 : F() : Enter the critical section. (Thread 1 is in)
Thread 1 : f_sub() : Enter the critical section. (Thread 1 is in)
Thread 1 : f_sub() : Leave the critical section. (Thread 1 is out)
Thread 2 : F() : Enter the critical section. (Thread 2 is in)
=> WRONG! Thread 2 should be forced to wait for Thread 1 leaving the critical section via F().
我的分析正确吗?这是否意味着建议主功能和子功能有不同的关键部分?