Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. HANDLE ThreadHandles[32];
  6. DWORD
  7. WorkerThread(
  8. PVOID ThreadIndex
  9. )
  10. {
  11. DWORD Processor;
  12. BOOL DoSleep;
  13. Processor = (DWORD)ThreadIndex;
  14. if ( Processor > 100 ) {
  15. DoSleep = TRUE;
  16. Processor -= 100;
  17. }
  18. else {
  19. DoSleep = FALSE;
  20. }
  21. SetThreadAffinityMask(GetCurrentThread(),1 << Processor);
  22. for(;;){
  23. if ( Processor & 1 ) {
  24. SetThreadPriority(ThreadHandles[Processor-1],THREAD_PRIORITY_ABOVE_NORMAL);
  25. SetThreadPriority(ThreadHandles[Processor-1],THREAD_PRIORITY_NORMAL);
  26. }
  27. else {
  28. if ( DoSleep ) {
  29. Sleep(0);
  30. }
  31. }
  32. }
  33. return 0;
  34. }
  35. int __cdecl
  36. main(
  37. int argc,
  38. char *argv[],
  39. char *envp[]
  40. )
  41. {
  42. DWORD i;
  43. SYSTEM_INFO SystemInfo;
  44. DWORD ThreadId;
  45. HANDLE hThread;
  46. GetSystemInfo(&SystemInfo);
  47. if ( SystemInfo.dwNumberOfProcessors >= 3 ) {
  48. for ( i=0;i<SystemInfo.dwNumberOfProcessors;i++) {
  49. ThreadHandles[i] = CreateThread(
  50. NULL,
  51. 0,
  52. WorkerThread,
  53. (PVOID)(i),
  54. 0,
  55. &ThreadId
  56. );
  57. if ( !ThreadHandles[i] ) {
  58. fprintf(stdout,"CreateThread failed %d\n",GetLastError());
  59. ExitProcess(1);
  60. }
  61. }
  62. for ( i=0;i<SystemInfo.dwNumberOfProcessors;i++) {
  63. if ( (i & 1) == 0 ) {
  64. hThread = CreateThread(
  65. NULL,
  66. 0,
  67. WorkerThread,
  68. (PVOID)(100+i),
  69. 0,
  70. &ThreadId
  71. );
  72. if ( !ThreadHandles[i] ) {
  73. fprintf(stdout,"CreateThread failed %d\n",GetLastError());
  74. ExitProcess(1);
  75. }
  76. CloseHandle(hThread);
  77. }
  78. }
  79. Sleep(60000);
  80. }
  81. ExitProcess(1);
  82. }