summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c
blob: acbb1ff37325670a8e9b90f8fc670463da9e7748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
** Source: getcurrentthreadid/test1/threadid.c
**
** Purpose: Test to ensure GetCurrentThreadId returns the threadId of the
** current thread. 
** 
** Dependencies: CloseHandle
**               WaitForSingleObject
**               CreateThread
** 

**
**=========================================================*/


#include <palsuite.h>

DWORD dwThreadIdTF;

DWORD PALAPI ThreadFunction ( LPVOID lpParam )
{
    Trace ("thread code executed\n");
    dwThreadIdTF = GetCurrentThreadId();
    return 0;
}

int __cdecl main( int argc, char **argv ) 
{
    extern DWORD dwThreadIdTF;
    DWORD dwThreadIdCT;
    HANDLE hThread; 
    DWORD dwThreadParam = 1;
    DWORD dwThreadWait;
    
    if(0 != (PAL_Initialize(argc, argv)))
    {
        return ( FAIL );
    }
    
    hThread = CreateThread(
        NULL,            
        0,               
        ThreadFunction,  
        &dwThreadParam,  
        0,               
        &dwThreadIdCT);  
    
    if ( NULL == hThread ) 
    {
        Fail ( "CreateThread() call failed - returned NULL");
    }
    else 
    {
	dwThreadWait = WaitForSingleObject( hThread, INFINITE );   
    
        Trace ("dwThreadWait returned %d\n", dwThreadWait );
    
	if ( dwThreadIdCT == dwThreadIdTF )
	{
            Trace ( "ThreadId numbers match - GetCurrentThreadId"
		     " works.  dwThreadIdCT == dwThreadIdTF == %d\n",
		     dwThreadIdTF );
	    PAL_Terminate();
            return ( PASS );
	}
	else 
	{
            Fail ( "ThreadId numbers don't match - "
		     "GetCurrentThreadId fails dwThreadIdCT = %d "
		     "and dwThreadIdTF = %d\n", dwThreadIdCT, dwThreadIdTF);
	}
    }

    PAL_TerminateEx(FAIL);
    return (FAIL);

}