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: getcurrentthreadid/test1/threadid.c
8**
9** Purpose: Test to ensure GetCurrentThreadId returns the threadId of the
10** current thread.
11**
12** Dependencies: CloseHandle
13** WaitForSingleObject
14** CreateThread
15**
16
17**
18**=========================================================*/
19
20
21#include <palsuite.h>
22
23DWORD dwThreadIdTF;
24
25DWORD PALAPI ThreadFunction ( LPVOID lpParam )
26{
27 Trace ("thread code executed\n");
28 dwThreadIdTF = GetCurrentThreadId();
29 return 0;
30}
31
32int __cdecl main( int argc, char **argv )
33{
34 extern DWORD dwThreadIdTF;
35 DWORD dwThreadIdCT;
36 HANDLE hThread;
37 DWORD dwThreadParam = 1;
38 DWORD dwThreadWait;
39
40 if(0 != (PAL_Initialize(argc, argv)))
41 {
42 return ( FAIL );
43 }
44
45 hThread = CreateThread(
46 NULL,
47 0,
48 ThreadFunction,
49 &dwThreadParam,
50 0,
51 &dwThreadIdCT);
52
53 if ( NULL == hThread )
54 {
55 Fail ( "CreateThread() call failed - returned NULL");
56 }
57 else
58 {
59 dwThreadWait = WaitForSingleObject( hThread, INFINITE );
60
61 Trace ("dwThreadWait returned %d\n", dwThreadWait );
62
63 if ( dwThreadIdCT == dwThreadIdTF )
64 {
65 Trace ( "ThreadId numbers match - GetCurrentThreadId"
66 " works. dwThreadIdCT == dwThreadIdTF == %d\n",
67 dwThreadIdTF );
68 PAL_Terminate();
69 return ( PASS );
70 }
71 else
72 {
73 Fail ( "ThreadId numbers don't match - "
74 "GetCurrentThreadId fails dwThreadIdCT = %d "
75 "and dwThreadIdTF = %d\n", dwThreadIdCT, dwThreadIdTF);
76 }
77 }
78
79 PAL_TerminateEx(FAIL);
80 return (FAIL);
81
82}
83