1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*=========================================================== |
6 | ** |
7 | ** Source: test3.c |
8 | ** |
9 | ** Purpose: Check to see that the handle CreateThread returns |
10 | ** can be closed while the thread is still running. |
11 | ** |
12 | ** |
13 | **=========================================================*/ |
14 | |
15 | #include <palsuite.h> |
16 | |
17 | HANDLE hThread; |
18 | HANDLE hEvent; |
19 | |
20 | DWORD PALAPI Thread( LPVOID lpParameter) |
21 | { |
22 | DWORD dwRet; |
23 | dwRet = WaitForSingleObject(hEvent, INFINITE); |
24 | /* if this thread continues beyond here, fail */ |
25 | Fail("" ); |
26 | |
27 | return 0; |
28 | } |
29 | |
30 | int __cdecl main(int argc, char **argv) |
31 | { |
32 | DWORD dwThreadId; |
33 | DWORD dwRet; |
34 | |
35 | if(0 != (PAL_Initialize(argc, argv))) |
36 | { |
37 | return (FAIL); |
38 | } |
39 | |
40 | hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); |
41 | |
42 | if (hEvent == NULL) |
43 | { |
44 | Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " |
45 | "returned %u.\n" , GetLastError()); |
46 | } |
47 | |
48 | /* pass the index as the thread argument */ |
49 | hThread = CreateThread( NULL, |
50 | 0, |
51 | &Thread, |
52 | (LPVOID) 0, |
53 | 0, |
54 | &dwThreadId); |
55 | if (hThread == NULL) |
56 | { |
57 | Trace("PALSUITE ERROR: CreateThread('%p' '%d' '%p' '%p' '%d' '%p') " |
58 | "call failed.\nGetLastError returned '%u'.\n" , NULL, |
59 | 0, &Thread, (LPVOID) 0, 0, &dwThreadId, GetLastError()); |
60 | if (0 == CloseHandle(hEvent)) |
61 | { |
62 | Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " |
63 | "clean up.\nGetLastError returned '%u'.\n" , hEvent); |
64 | } |
65 | Fail("" ); |
66 | } |
67 | |
68 | dwRet = WaitForSingleObject(hThread, 10000); |
69 | if (dwRet != WAIT_TIMEOUT) |
70 | { |
71 | Trace ("PALSUITE ERROR: WaitForSingleObject('%p' '%d') " |
72 | "call returned %d instead of WAIT_TIMEOUT ('%d').\n" |
73 | "GetLastError returned '%u'.\n" , hThread, 10000, |
74 | dwRet, WAIT_TIMEOUT, GetLastError()); |
75 | Fail("" ); |
76 | } |
77 | |
78 | if (0 == CloseHandle(hThread)) |
79 | { |
80 | Trace("PALSUITE ERROR: Unable to CloseHandle(%p) on a running thread." |
81 | "\nGetLastError returned '%u'.\n" , hThread, GetLastError()); |
82 | if (0 == CloseHandle(hEvent)) |
83 | { |
84 | Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " |
85 | "cleanup.\nGetLastError returned '%u'.\n" , hEvent, |
86 | GetLastError()); |
87 | } |
88 | Fail("" ); |
89 | } |
90 | if (0 == CloseHandle(hEvent)) |
91 | { |
92 | Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " |
93 | "cleanup.\nGetLastError returned '%u'.\n" , hEvent, |
94 | GetLastError()); |
95 | Fail("" ); |
96 | } |
97 | |
98 | PAL_Terminate(); |
99 | return (PASS); |
100 | } |
101 | |
102 | |