3 #include <winpr/synch.h>
4 #include <winpr/thread.h>
6 static DWORD WINAPI test_thread(LPVOID arg)
14 int TestSynchThread(
int argc,
char* argv[])
22 thread = CreateThread(NULL, 0, test_thread, NULL, 0, NULL);
26 printf(
"CreateThread failure\n");
31 rc = WaitForSingleObject(thread, 0);
33 if (WAIT_TIMEOUT != rc)
35 printf(
"Timed WaitForSingleObject on running thread failed with %" PRIu32
"\n", rc);
40 rc = WaitForSingleObject(thread, INFINITE);
42 if (WAIT_OBJECT_0 != rc)
44 printf(
"WaitForSingleObject on thread failed with %" PRIu32
"\n", rc);
49 rc = WaitForSingleObject(thread, 0);
51 if (WAIT_OBJECT_0 != rc)
53 printf(
"Timed WaitForSingleObject on dead thread failed with %" PRIu32
"\n", rc);
58 for (
int i = 0; i < 4; i++)
60 rc = WaitForSingleObject(thread, 0);
61 if (WAIT_OBJECT_0 != rc)
63 printf(
"Timed WaitForSingleObject on dead thread failed with %" PRIu32
"\n", rc);
68 if (!CloseHandle(thread))
70 printf(
"CloseHandle failed!");
74 thread = CreateThread(NULL, 0, test_thread, NULL, 0, NULL);
78 printf(
"CreateThread failure\n");
83 rc = WaitForSingleObject(thread, 10);
85 if (WAIT_TIMEOUT != rc)
87 printf(
"Timed WaitForSingleObject on running thread failed with %" PRIu32
"\n", rc);
92 rc = WaitForSingleObject(thread, INFINITE);
94 if (WAIT_OBJECT_0 != rc)
96 printf(
"WaitForSingleObject on thread failed with %" PRIu32
"\n", rc);
101 rc = WaitForSingleObject(thread, 0);
103 if (WAIT_OBJECT_0 != rc)
105 printf(
"Timed WaitForSingleObject on dead thread failed with %" PRIu32
"\n", rc);
109 if (!CloseHandle(thread))
111 printf(
"CloseHandle failed!");
116 thread = CreateThread(NULL, 0, test_thread, NULL, 0, NULL);
120 printf(
"CreateThread failure\n");
124 if (!CloseHandle(thread))
126 printf(
"CloseHandle failed!");