exempleThread2.c 723 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "Header.h"
  2. int n = 10;
  3. DWORD WINAPI ThreadFactorial(LPVOID param)
  4. {
  5. int f = 0;
  6. for (int i = 0; i < n; i++)
  7. {
  8. if (i == 0) f = 1;
  9. else f *= i;
  10. printf("Ôàêòîðèàë %d = %d\n", i, f);
  11. }
  12. ExitThread(0);
  13. }
  14. DWORD WINAPI ThreadFibonachi(LPVOID param)
  15. {
  16. int buf = 0;
  17. int f1 = 1;
  18. int f2 = 1;
  19. for (int i = 0; i < n; i++)
  20. {
  21. if (i > 2)
  22. {
  23. buf = f1;
  24. f1 = f2;
  25. f2 += buf;
  26. }
  27. printf("%d ýëåìåíò Ôèáîíà÷è = %d\n", i, f2);
  28. }
  29. ExitThread(0);
  30. }
  31. VOID funcThread(VOID)
  32. {
  33. HANDLE hT[2];
  34. hT[0] = CreateThread(NULL, 0, ThreadFactorial, NULL, 0, 0);
  35. hT[1] = CreateThread(NULL, 0, ThreadFibonachi, NULL, 0, 0);
  36. WaitForMultipleObjects(2, hT, TRUE, INFINITE);
  37. }
  38. void secondExemple()
  39. {
  40. funcThread();
  41. }