update for HEAD-2003091401
[reactos.git] / apps / tests / suspend / suspend.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      printf("I should have been suspended for years :-)\n");
25      Sleep(100);
26      x=0;y++;
27      if(y==3) ExitProcess(0);
28    }
29   }
30 }
31
32 int
33 main(int argc, char *argv[])
34 {
35   HANDLE thread;
36   DWORD thread_id;
37   CONTEXT context;
38
39   context.ContextFlags=CONTEXT_CONTROL;
40
41   z=0;
42   thread=CreateThread(NULL,
43                       0x1000,
44                       thread_1,
45                       NULL,
46                       0,
47                       &thread_id);
48
49   if(!thread)
50   {
51     printf("Error: could not create thread ...\n");
52     ExitProcess(0);
53   }
54
55   Sleep(1000);
56
57   SuspendThread(thread);
58
59   for(;;)
60   {
61     printf("%x ", z);
62     Sleep(100);x++;
63     if(x>100 && GetThreadContext(thread, &context))
64     {
65       printf("EIP: %x\n", context.Eip);
66       printf("Calling resumethread ... \n");
67       ResumeThread(thread);
68     }
69   }
70
71   ExitProcess(0);
72   return(0);
73 }