Advertisement
dzieciol

PRiR tworzenie wątków 1

Feb 27th, 2018
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <boost/thread/thread.hpp>
  4. #include <unistd.h>
  5.  
  6. using namespace std;
  7.  
  8. #define LICZBAPUNKTOW 10
  9.  
  10. double a = 0;
  11. double b = M_PI;
  12. double wynik = 0.0;
  13.  
  14. void calkaSinus() {
  15.     cout << "wątek pracuje..." << endl;
  16.     double h = (b - a);
  17.     double s = sin(a);
  18.     for (int i = 1; i < LICZBAPUNKTOW; i++) {
  19.         usleep(1000);
  20.         s += s * sin(a + i * h);
  21.     }
  22.     s += s * sin(b);
  23.  
  24.     wynik = s * h / 2;
  25.  
  26.     cout << "wątek się zakończył" << endl;
  27. }
  28.  
  29.  
  30. int main() {
  31.     boost::thread watek(calkaSinus);
  32.     cout << "Sprzętowa współbierzność" << boost::thread::hardware_concurrency() << endl;
  33.     cout << "ID wątku:" << watek.get_id() << endl;
  34.     watek.join();
  35.  
  36.     cout << "wynik= " << wynik << endl;
  37.  
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement