Question about resuming suspended thread by using event in C and W



Dear all,

I have one problem about resuming suspended thread by using event in C and
WINAPI. The snippet of code is as follows, can you help me to point out the
incorrects?

DWORD WINAPI ThreadFunction()
{
while(1)
{
ResetEvent(hGlobalWriteEvent);
WaitForSingleObject(hGlobalWriteEvent, INFINITE);
printf("Thread test is resumed.");
return 0;
}

}

void CreateEventsAndThreads(void)
{
DWORD IDThread;
hGlobalWriteEvent = CreateEvent(
NULL, // default security
attributes
TRUE, // manual-reset event
FALSE, // initial state is
nonsignaled
"WriteEvent" // object name
);

if (hGlobalWriteEvent == NULL)
{
printf("CreateEvent failed (%d)\n", GetLastError());
}

hThread = CreateThread(NULL, 0, ThreadFunction,
&hGlobalWriteEvent, // pass
event handle
CREATE_SUSPENDED,&IDThread);

if (hThread == NULL) {
printf("CreateThread failed (%d)\n", GetLastError());
}

SetEvent(hGlobalWriteEvent);
}

void main(void)
{
....
CreateEventsAndThreads();
}

.


Loading