如何修复SleepConditionVariableCS始终返回1?

时间:2019-05-21 10:00:26

标签: c

我尝试编写一些有关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(&section);
        if (SleepConditionVariableCS(&variable, &section, 1000))
        {
            printf("oh dear!:%d\n", GetLastError());
        }
        LeaveCriticalSection(&section);
    }
    return 0;
}

int main()
{
    HANDLE hd = 0;

    InitializeCriticalSection(&section);
    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将打印很多次

0 个答案:

没有答案