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.

154 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. taststrs.c
  5. Abstract:
  6. Tasking stress test.
  7. Author:
  8. Mark Lucovsky (markl) 26-Sep-1990
  9. Revision History:
  10. --*/
  11. #include <assert.h>
  12. #include <stdio.h>
  13. #include <windows.h>
  14. #include <string.h>
  15. HANDLE Semaphore, Event;
  16. VOID
  17. TestThread(
  18. LPVOID ThreadParameter
  19. )
  20. {
  21. DWORD st;
  22. (ReleaseSemaphore(Semaphore,1,NULL));
  23. st = WaitForSingleObject(Event,500);
  24. ExitThread(0);
  25. }
  26. VOID
  27. NewProcess()
  28. {
  29. DWORD st;
  30. DWORD ThreadId;
  31. HANDLE Thread;
  32. DWORD NumberOfThreads;
  33. DWORD MaximumThreadCount;
  34. DWORD i;
  35. //
  36. // Create an Event that is never signaled
  37. //
  38. Event = CreateEvent(NULL,TRUE,FALSE,NULL);
  39. //
  40. // Create a semaphore signaled by each thread as it starts
  41. //
  42. Semaphore = CreateSemaphore(NULL,0,256,NULL);
  43. (Event);
  44. (Semaphore);
  45. MaximumThreadCount = 15;
  46. NumberOfThreads = 0;
  47. //
  48. // Create the threads
  49. //
  50. printf("Creating %d threads... ",MaximumThreadCount);
  51. for ( i = 0;i<MaximumThreadCount;i++ ) {
  52. Thread = CreateThread(NULL,0L,(PVOID)TestThread,(LPVOID)99,0,&ThreadId);
  53. if ( Thread ) {
  54. NumberOfThreads++;
  55. CloseHandle(Thread);
  56. }
  57. }
  58. printf("%d threads Created\n",NumberOfThreads);
  59. for(i=0;i<NumberOfThreads;i++) {
  60. st = WaitForSingleObject((HANDLE)Semaphore,(DWORD)-1);
  61. (st == 0);
  62. }
  63. Sleep(3000);
  64. TerminateProcess(GetCurrentProcess(),0);
  65. }
  66. DWORD
  67. _cdecl
  68. main(
  69. int argc,
  70. char *argv[],
  71. char *envp[]
  72. )
  73. {
  74. STARTUPINFO StartupInfo;
  75. PROCESS_INFORMATION ProcessInfo;
  76. BOOL Success;
  77. DWORD st;
  78. DWORD ProcessCount;
  79. SMALL_RECT Window;
  80. ProcessCount = 0;
  81. if ( strchr(GetCommandLine(),'+') ) {
  82. NewProcess();
  83. }
  84. GetStartupInfo(&StartupInfo);
  85. Window.Left = 0;
  86. Window.Top = 0;
  87. Window.Right = 15;
  88. Window.Bottom = 5;
  89. SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE),
  90. TRUE,
  91. &Window
  92. );
  93. while ( TRUE ) {
  94. Success = CreateProcess(
  95. NULL,
  96. "taskstrs +",
  97. NULL,
  98. NULL,
  99. FALSE,
  100. CREATE_NEW_CONSOLE,
  101. NULL,
  102. NULL,
  103. &StartupInfo,
  104. &ProcessInfo
  105. );
  106. if (Success) {
  107. ProcessCount++;
  108. printf("Process %d Created\n",ProcessCount);
  109. st = WaitForSingleObject((HANDLE)ProcessInfo.hProcess,(DWORD)-1);
  110. (st == 0);
  111. CloseHandle(ProcessInfo.hProcess);
  112. CloseHandle(ProcessInfo.hThread);
  113. }
  114. }
  115. return TRUE;
  116. }