简单学习测试用例
/* 信号量 */
#include <Windows.h>
#include <stdio.h>
#define Second 1000
#define TEST
DWORD thProc(LPVOID Hsem)
{
while (1)
{
WaitForSingleObject(Hsem, INFINITE);
printf("I'm happy!\n");
}
}
int main(void)
{
DWORD thID;
HANDLE Hsem = CreateSemaphore(0, 3, 10, NULL);
HANDLE Hth = CreateThread(0, 1, thProc, Hsem, 0, &thID);
while (1)
{
Sleep(2 * Second);
#ifdef TEST
printf("Reset!\n");
// 重置信号量
ReleaseSemaphore(Hsem, 4, NULL);
#else
CloseHandle(Hsem);
CloseHandle(Hth);
break;
#endif
}
return 0;
}