SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <ctime>
  5. #include <windows.h>
  6. #include <iostream>
  7. #include <string>
  8. using namespace std;
  9. static long s;
  10. static long p;
  11. DWORD WINAPI ThreadFunction(PVOID Parametr1)
  12. {
  13.     const int size = 50;
  14.     int a[15][15];
  15.     srand(time(0));
  16.     long proizv = 1; // результат произведения
  17.     int ii, *kk, sum = 0, pro = 1;
  18.     kk = (int*)Parametr1;
  19.     for (int x = 0; x < *kk; x++)
  20.         for (int y = 0; y < *kk; y++) {
  21.             a[x][y] = 1 + rand() % 100;
  22.             sum += a[x][y];
  23.             pro *= a[x][y];
  24.         }
  25.     s = sum;
  26.     p = pro;
  27.     return sum;
  28.     return pro;
  29. }
  30. int main()
  31. {
  32.     DWORD idThread;
  33.     int k1, k2 = 5;
  34.     HANDLE h1, h2;
  35.     //cout << "K1 = >  ";
  36.     //cin >> k1;
  37.     // Создается два потока в приостановленном состоянии
  38.     h1 = CreateThread(NULL, 0, ThreadFunction, &k1, CREATE_SUSPENDED, &idThread);
  39.     SetThreadPriority(&k1, THREAD_PRIORITY_IDLE);
  40.     h2 = CreateThread(NULL, 0, ThreadFunction, &k2, CREATE_SUSPENDED, &idThread);
  41.     SetThreadPriority(&k2, THREAD_PRIORITY_TIME_CRITICAL);
  42.     // Выполнение потоков
  43.     ResumeThread(h1);
  44.     ResumeThread(h2);
  45.     WaitForSingleObject(h1, INFINITE);
  46.     cout << "summa= " << s;
  47.     cout << "\nproizvedenie= " << p << endl;
  48.     system("PAUSE");
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top