Source code of Windows XP (NT5)
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.

129 lines
2.7 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #define TOTAL_COUNT (100000000)
  6. //
  7. // DON'T UNCOMMENT THIS LINE UNTIL YOU'RE READY
  8. // TO RUN THE WHOLE TEST. YOU WON'T BE ABLE TO
  9. // BREAK IN UNTIL THE TEST ENDS!!!
  10. //
  11. #define GO_FOREVER (1)
  12. #define MAX_MEMORY (256)
  13. DWORD
  14. MyWorkerThread(
  15. PVOID ThreadParameter
  16. )
  17. /*++
  18. Pretend to be busy.
  19. --*/
  20. {
  21. ULONG i;
  22. PVOID TmpPtr = NULL;
  23. ULONG MemorySize;
  24. #ifdef GO_FOREVER
  25. while( 1 ) {
  26. #else
  27. for( i = 0; i < TOTAL_COUNT; i++ ) {
  28. #endif
  29. MemorySize = rand() % MAX_MEMORY;
  30. }
  31. return 0;
  32. }
  33. int
  34. __cdecl
  35. main( int argc, char *argv[])
  36. {
  37. ULONG i;
  38. DWORD ThreadId;
  39. SYSTEM_INFO SystemInfo;
  40. HANDLE MyHandle;
  41. HANDLE *HandlePtr = NULL;
  42. printf( "This program is for testing purposes only.\n" );
  43. printf( "It is designed to consume all available CPU cycles.\n" );
  44. printf( "\n" );
  45. printf( "IT WILL RENDER YOUR SYSTEM UNRESPONSIVE!\n" );
  46. printf( "\n" );
  47. printf( "Press the '+' key to continue, or any other key to exit.\n" );
  48. if( _getch() != '+' ) {
  49. printf( "Exiting...\n" );
  50. return;
  51. }
  52. printf( "working..." );
  53. //
  54. // Figure out how many CPUs we have. We'll want to create a thread
  55. // for each one so that there is no available resources.
  56. //
  57. GetSystemInfo( &SystemInfo );
  58. //
  59. // Allocate an array of handles for each one of the processors.
  60. //
  61. HandlePtr = (HANDLE *)malloc( sizeof(HANDLE) * SystemInfo.dwNumberOfProcessors );
  62. if( HandlePtr == NULL ) {
  63. printf( "We failed to allocate any memory.\n" );
  64. return;
  65. }
  66. //
  67. // Let this guy get lots of CPU time.
  68. //
  69. if (!SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS)) {
  70. printf("Failed to raise to realtime priority\n");
  71. }
  72. //
  73. // Now go create a bunch of threads so that we tie up all available time
  74. // on all CPUs.
  75. //
  76. for( i = 0; i < SystemInfo.dwNumberOfProcessors; i++ ) {
  77. HandlePtr[i] = CreateThread( NULL,
  78. 0,
  79. MyWorkerThread,
  80. UIntToPtr( i ),
  81. CREATE_SUSPENDED,
  82. &ThreadId );
  83. if( HandlePtr[i] != NULL ) {
  84. SetThreadPriority( HandlePtr[i],
  85. THREAD_PRIORITY_TIME_CRITICAL );
  86. ResumeThread( HandlePtr[i] );
  87. }
  88. }
  89. //
  90. // Now wait for them to finish.
  91. //
  92. WaitForMultipleObjects( SystemInfo.dwNumberOfProcessors,
  93. HandlePtr,
  94. TRUE,
  95. INFINITE );
  96. }