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", PtrToUlong(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", PtrToUlong(param));
20    Sleep(INFINITE);
21    return 0;
22 }
23 
24 
25 int main (void)
26 {
27    DWORD i=0;
28    DWORD id;
29 
30 #if 1
31    printf("Creating %d threads...\n",NR_THREADS*2);
32    for (i=0;i<NR_THREADS;i++)
33      {
34 	CreateThread(NULL,
35 		     0,
36 		     thread_main1,
37 		     (LPVOID)(ULONG_PTR)i,
38 		     0,
39 		     &id);
40 
41 /*	CreateThread(NULL,
42 		     0,
43 		     thread_main2,
44 		     (LPVOID)i,
45 		     0,
46 		     &id);*/
47      }
48 
49    printf("All threads created...\n");
50 
51    /*
52     * Waiting for threads is not implemented yet.
53     * If you want to see all threads running, uncomment the
54     * call to SuspendThread(). The test application will
55     * freeze after all threads are created.
56     */
57 /*   SuspendThread (GetCurrentThread()); */
58 
59 #else
60 
61    printf("Creating thread...\n");
62 
63    hThread = CreateThread(NULL,
64                           0,
65                           thread_main1,
66                           (LPVOID)i,
67                           0,
68                           &id);
69 
70    printf("Thread created. Waiting for termination...\n");
71 
72    WaitForSingleObject (hThread,
73                         -1);
74 
75    CloseHandle (hThread);
76 
77    printf("Thread terminated...\n");
78 #endif
79    printf("Exiting\n");
80    return 0;
81 }
82