:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / apps / tests / bench / bench-thread.c
1 #include <stdio.h>
2 #include <windows.h>
3
4 #define NR_THREADS (30)
5
6
7 DWORD WINAPI
8 thread_main1(LPVOID param)
9 {
10    printf("Thread 1 running (Counter %lu)\n", (DWORD)param);
11    SleepEx(INFINITE, TRUE);
12    return 0;
13 }
14
15
16 DWORD WINAPI
17 thread_main2(LPVOID param)
18 {
19    printf("Thread 2 running (Counter %lu)\n", (DWORD)param);
20    Sleep(INFINITE);
21    return 0;
22 }
23
24
25 int main (void)
26 {
27    HANDLE hThread;
28    DWORD i=0;
29    DWORD id;
30
31 #if 1
32    printf("Creating %d threads...\n",NR_THREADS*2);
33    for (i=0;i<NR_THREADS;i++)
34      {
35         CreateThread(NULL,
36                      0,
37                      thread_main1,
38                      (LPVOID)i,
39                      0,
40                      &id);
41
42 /*      CreateThread(NULL,
43                      0,
44                      thread_main2,
45                      (LPVOID)i,
46                      0,
47                      &id);*/
48      }
49
50    printf("All threads created...\n");
51    
52    /*
53     * Waiting for threads is not implemented yet.
54     * If you want to see all threads running, uncomment the
55     * call to SuspendThread(). The test application will
56     * freeze after all threads are created.
57     */
58 /*   SuspendThread (GetCurrentThread()); */
59
60 #else
61
62    printf("Creating thread...\n");
63
64    hThread = CreateThread(NULL,
65                           0,
66                           thread_main1,
67                           (LPVOID)i,
68                           0,
69                           &id);
70
71    printf("Thread created. Waiting for termination...\n");
72
73    WaitForSingleObject (hThread,
74                         -1);
75
76    CloseHandle (hThread);
77
78    printf("Thread terminated...\n");
79 #endif
80    printf("Exiting\n");
81    return 0;
82 }