This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / apps / tests / terminate / terminate.c
1 #define UNICODE
2
3 #define NTOS_MODE_USER
4 #include <ntos.h>
5 #include <windows.h>
6
7 #define DBG
8 #define NDEBUG
9 #include <debug.h>
10
11 static volatile DWORD z;
12 static volatile DWORD x=0;
13
14 static NTSTATUS STDCALL
15 thread_1(PVOID Param)
16 {
17   DWORD y=0;
18
19   for(;;)
20   {
21    z++;
22    if(x>50)
23    {
24      Sleep(100);
25      x=0;y++;
26      if(y==3) return(0);
27    }
28   }
29 }
30
31 int
32 main(int argc, char *argv[])
33 {
34   HANDLE thread;
35   DWORD thread_id;
36   CONTEXT context;
37   DWORD z = 0;
38
39   context.ContextFlags=CONTEXT_CONTROL;
40   
41   while (z < 50)
42     {
43       TerminateThread(thread, 0);
44       z++;
45       thread=CreateThread(NULL,
46                           0x1000,
47                           thread_1,
48                           NULL,
49                           0,
50                           &thread_id);
51       
52       if(!thread)
53         {
54           printf("Error: could not create thread ...\n");
55           ExitProcess(0);
56         }
57       
58       Sleep(1000);
59       
60       printf("T");
61       if ((z % 5) == 0)
62         {
63           TerminateThread(thread, 0);
64         }
65       printf("C");
66       GetThreadContext(thread, &context);
67       printf("S");
68       SuspendThread(thread);
69       printf("R");
70       ResumeThread(thread);      
71     }
72
73   ExitProcess(0);
74   return(0);
75 }