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