Reactos
1#include <stdio.h>
2#include <windows.h>
3#include <stdlib.h>
4
5#define NR_THREADS (10)
6
7ULONG nr;
8
9DWORD WINAPI thread_main1(LPVOID param)
10{
11 ULONG s;
12
13 printf("Thread %ld running\n", (DWORD)param);
14 s = nr = ((nr * 1103515245) + 12345) & 0x7fffffff;
15 s = s % 10;
16 printf("s %ld\n", s);
17 Sleep(s);
18 printf("Thread %ld finished\n", (DWORD)param);
19 return 0;
20}
21
22// Shows the help on how to use these program to the user
23void showHelp(void)
24{
25
26printf("\nReactOS threads test program (built on %s).\n\n", __DATE__);
27printf("syntax:\tthread.exe <seed>\n");
28printf("\twhere <seed> is an integer number\n");
29printf("\texample: thread.exe 100\n");
30
31
32}
33
34int main (int argc, char* argv[])
35{
36 DWORD i=0;
37 DWORD id;
38 ULONG nr;
39 HANDLE ThreadHandle[NR_THREADS];
40
41 // The user must supply one argument (the seed). if he/she doesn't
42 // then we show the help.
43 // if(argc < 2) {
44 // showHelp();
45 // return 1;
46 // }
47
48 // nr = atoi(argv[1]);
49 nr = 500;
50 printf("Seed %ld\n", nr);
51
52 printf("Creating %d threads...\n",NR_THREADS*2);
53 for (i=0;i<NR_THREADS;i++)
54 {
55 ThreadHandle[i] = CreateThread(NULL,
56 0,
57 thread_main1,
58 (LPVOID)i,
59 CREATE_SUSPENDED,
60 &id);
61
62 }
63
64 for (i=0;i<NR_THREADS;i++)
65 {
66 ResumeThread(ThreadHandle[i]);
67 }
68
69 for (i=0;i<NR_THREADS;i++)
70 {
71 SuspendThread(ThreadHandle[i]);
72 }
73
74 for (i=0;i<NR_THREADS;i++)
75 {
76 ResumeThread(ThreadHandle[i]);
77 }
78
79 printf("All threads created...\n");
80 return 0;
81}