Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include "windows.h"
  2. #include "stdio.h"
  3. #include "conio.h"
  4. #include "stdint.h"
  5.  
  6. BYTE asmOfNopFunction[2] =
  7. {
  8.     0x90,
  9.     0xC3
  10. };
  11.  
  12. int main()
  13. {
  14.     const int NUMBER_OF_MEANINGS = 5;
  15.     const int NUMBER_OF_THREADS = 1000;
  16.  
  17.     float createThreadTimings[NUMBER_OF_MEANINGS];
  18.     HANDLE threadHandles[NUMBER_OF_THREADS];
  19.     int64_t qpf, start, stop;
  20.     QueryPerformanceFrequency((LARGE_INTEGER*)&qpf);
  21.  
  22.     SetLastError(10101);
  23.     for(int currentMeaningOfSuspendedThreads = 0; currentMeaningOfSuspendedThreads < NUMBER_OF_MEANINGS; currentMeaningOfSuspendedThreads++)
  24.     {
  25.         QueryPerformanceCounter((LARGE_INTEGER*)&start);
  26.         for(int currentThread = 0; currentThread < NUMBER_OF_THREADS; currentThread++)
  27.         {
  28.             threadHandles[currentThread] = CreateThread(0, 8, &asmOfNopFunction, 0, CREATE_SUSPENDED, 0);
  29.             printf("thr%i-handle%i\n", currentThread, threadHandles[currentThread]);
  30.             TerminateThread(threadHandles[currentThread], 0);
  31.         }
  32.         QueryPerformanceCounter((LARGE_INTEGER*)&stop);
  33.         createThreadTimings[currentMeaningOfSuspendedThreads] = (stop - start) / (float)qpf;
  34.     }
  35.     int j = GetLastError();
  36.  
  37.    
  38.  
  39.     SetLastError(10102);
  40.     for(int currentMeaningOfWorkingThreads = 0; currentMeaningOfWorkingThreads < NUMBER_OF_MEANINGS; currentMeaningOfWorkingThreads++)
  41.     {
  42.         for(int currentThread = 0; currentThread < NUMBER_OF_THREADS; currentThread++)
  43.         {
  44.             threadHandles[currentThread] = CreateThread(0, 0, &asmOfNopFunction, 0, CREATE_SUSPENDED, 0);
  45.             printf("thr%i-handle%i\n", currentThread, threadHandles[currentThread]);
  46.             TerminateThread(threadHandles[currentThread], 0);
  47.         }
  48.     }
  49.     printf("Last error is %i", j);
  50.     printf("Last error is %i", GetLastError());
  51.  
  52.     ((void(*)())asmOfNopFunction)();
  53.     getch();
  54.     return;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement