FreeRDP
Loading...
Searching...
No Matches
TestThreadExitThread.c
1// Copyright © 2015 Hewlett-Packard Development Company, L.P.
2
3#include <winpr/file.h>
4#include <winpr/synch.h>
5#include <winpr/thread.h>
6
7static DWORD WINAPI thread_func(LPVOID arg)
8{
9 WINPR_UNUSED(arg);
10
11 /* exists of the thread the quickest as possible */
12 ExitThread(0);
13 return 0;
14}
15
16int TestThreadExitThread(int argc, char* argv[])
17{
18 HANDLE thread = NULL;
19 DWORD waitResult = 0;
20
21 WINPR_UNUSED(argc);
22 WINPR_UNUSED(argv);
23
24 /* FIXME: create some noise to better guaranty the test validity and
25 * decrease the number of loops */
26 for (int i = 0; i < 100; i++)
27 {
28 thread = CreateThread(NULL, 0, thread_func, NULL, 0, NULL);
29
30 if (thread == INVALID_HANDLE_VALUE)
31 {
32 (void)fprintf(stderr, "Got an invalid thread!\n");
33 return -1;
34 }
35
36 waitResult = WaitForSingleObject(thread, 300);
37 if (waitResult != WAIT_OBJECT_0)
38 {
39 /* When the thread exits before the internal thread_list
40 * was updated, ExitThread() is not able to retrieve the
41 * related WINPR_THREAD object and is not able to signal
42 * the end of the thread. Therefore WaitForSingleObject
43 * never get the signal.
44 */
45 (void)fprintf(
46 stderr, "300ms should have been enough for the thread to be in a signaled state\n");
47 return -1;
48 }
49
50 (void)CloseHandle(thread);
51 }
52 return 0;
53}