Facebook
From Ample Owl, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 324
  1. /*****************************************************************************
  2. *       APPLICATION:    _2_03b
  3. *       MODULE:                 main
  4. *       PURPOSE:
  5. *       AUTHOR(S):              damian.galczynski
  6. *
  7. *       5/11/2017 4:25:24 PM    Created.
  8. *****************************************************************************/
  9. #include <stdio.h>
  10. #include <Windows.h>
  11. #include "auxfunctions.h"
  12. /*****************************************************************************
  13. *       THE MAIN ENTRY POINT TO THE PROGRAM.
  14. *
  15. *       input:  argc    The number of arguments of the programme.
  16. *                       argv    The vector of arguments of the programme.
  17. *       return: The code of the reason the process was terminated for.
  18. *                       The value defaults to zero.
  19. *****************************************************************************/
  20. DWORD WINAPI threadA(void* params);
  21.  
  22. int main(int argc, char* argv[])
  23. {
  24.  
  25.         HANDLE WINAPI hThread;
  26.         DWORD tid = GetCurrentThreadId();
  27.  
  28.         hThread = CreateThread(NULL, 0, threadA, NULL, 0, &tid);
  29.         if (hThread)
  30.         {
  31.                 printf("Press any key to stop ...\n");
  32.                 getchar();
  33.                 CloseHandle(hThread);
  34.         }
  35.  
  36.         return 0;
  37. }
  38.  
  39. DWORD WINAPI threadA(void* params) {
  40.         const DWORD pid = GetCurrentProcessId();
  41.         const DWORD tid = GetCurrentThreadId();
  42.         const DWORD timeDeley = getDelayTime();
  43.  
  44.         DWORD exitCode;
  45.         int timeRemain;
  46.  
  47.         randomize();
  48.         timeRemain = getRunningTime(THRT_MIN, THRT_MAX);
  49.         printf("(EXE-2.03b)Watek A : %05lu:%05lu: Watek wystartowal. \n", pid, tid);
  50.         printf("                                  Opoznienie: %d\n", timeDeley);
  51.         printf("                                  Czas Startu: %d\n", timeRemain);
  52.  
  53.         do {
  54.                 printf("(EXE-2.03b)Watek A : %05lu:%05lu: %d\n", pid, tid, timeRemain);
  55.                 Sleep(timeDeley);
  56.                 timeRemain = timeRemain - timeDeley;
  57.         } while (timeRemain > 0);
  58.  
  59.         exitCode = makeCode();
  60.         printf("(EXE-2.03B)Watek A : %05lu:%05lu: Code: %lu""\n", pid, tid, exitCode);
  61.         return exitCode;
  62.  
  63. }