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: test1.c
8**
9** Purpose: Test to ensure YieldProcessor works, without
10** causing test to hang
11**
12** Dependencies: PAL_Initialize
13** Fail
14** YieldProcessor
15** WaitForMultipleObject
16** CreateThread
17** GetLastError
18**
19
20**
21**===========================================================================*/
22
23
24#include <palsuite.h>
25#define THREAD_COUNT 10
26#define REPEAT_COUNT 1000
27#define TIMEOUT 60000
28void PALAPI Run_Thread(LPVOID lpParam);
29
30/**
31 * main
32 *
33 * executable entry point
34 */
35INT __cdecl main( INT argc, CHAR **argv )
36{
37 DWORD dwParam;
38 HANDLE hThread[THREAD_COUNT];
39 DWORD threadId[THREAD_COUNT];
40
41 int i = 0;
42 int returnCode = 0;
43
44 /*PAL initialization */
45 if( (PAL_Initialize(argc, argv)) != 0 )
46 {
47 return FAIL;
48 }
49
50
51 for( i = 0; i < THREAD_COUNT; i++ )
52 {
53 dwParam = (int) i;
54 //Create thread
55 hThread[i] = CreateThread(
56 NULL, /* no security attributes */
57 0, /* use default stack size */
58 (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */
59 (LPVOID)dwParam, /* argument to thread function */
60 0, /* use default creation flags */
61 &threadId[i] /* returns the thread identifier*/
62 );
63
64 if(hThread[i] == NULL)
65 {
66 Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError());
67 }
68
69 }
70
71
72 returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, TIMEOUT);
73 if( WAIT_OBJECT_0 != returnCode )
74 {
75 Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError());
76 }
77
78 PAL_Terminate();
79 return PASS;
80
81}
82
83void PALAPI Run_Thread (LPVOID lpParam)
84{
85 int i = 0;
86
87 for(i=0; i < REPEAT_COUNT; i++ )
88 {
89 // No error code set nor does it have any return code
90 YieldProcessor();
91 }
92}
93