我尝试编写一些有关Windows条件变量的代码,但是发现SleepConditionVariableCS
返回1,即使未调用WakeConditionVariable
。
#include <process.h>
#include <Windows.h>
#include <stdio.h>
CRITICAL_SECTION section;
CONDITION_VARIABLE variable;
unsigned __stdcall WakeupAgain(void* arg)
{
while (1) {
EnterCriticalSection(§ion);
if (SleepConditionVariableCS(&variable, §ion, 1000))
{
printf("oh dear!:%d\n", GetLastError());
}
LeaveCriticalSection(§ion);
}
return 0;
}
int main()
{
HANDLE hd = 0;
InitializeCriticalSection(§ion);
InitializeConditionVariable(&variable);
hd = (HANDLE)_beginthreadex(NULL, 0, WakeupAgain, 0, 0, NULL);
hd = (HANDLE)_beginthreadex(NULL, 0, WakeupAgain, 0, 0, NULL);
hd = (HANDLE)_beginthreadex(NULL, 0, WakeupAgain, 0, 0, NULL);
while (1) {
}
return 0;
}
oh dear!:%0
将打印很多次