1 #define UNICODE 2 #define WIN32_NO_STATUS 3 #include <windows.h> 4 #include <stdio.h> 5 #define NTOS_MODE_USER 6 #include <ndk/ntndk.h> 7 8 #define NDEBUG 9 #include <debug.h> 10 11 static volatile DWORD z; 12 static volatile DWORD x=0; 13 14 static NTSTATUS WINAPI 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 z++; 44 thread=CreateThread(NULL, 45 0x1000, 46 (LPTHREAD_START_ROUTINE)thread_1, 47 NULL, 48 0, 49 &thread_id); 50 51 if(!thread) 52 { 53 printf("Error: could not create thread ...\n"); 54 ExitProcess(0); 55 } 56 57 Sleep(1000); 58 59 printf("T"); 60 if ((z % 5) == 0) 61 { 62 TerminateThread(thread, 0); 63 } 64 printf("C"); 65 GetThreadContext(thread, &context); 66 printf("S"); 67 SuspendThread(thread); 68 printf("R"); 69 ResumeThread(thread); 70 TerminateThread(thread, 0); 71 } 72 73 ExitProcess(0); 74 return(0); 75 } 76