Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 56 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <thread>
  2. #include <iostream>
  3. #include <vector>
  4. #include <numeric>
  5. #include <fstream>
  6. std::ofstream plik_wyj("plik.txt");
  7. bool odnaleziono = false;
  8.  
  9. void search_tab(const std::vector<int> &tab, int poc, int kon, int szuk)
  10. {
  11.  
  12.  
  13.         for (int i = poc; i < kon; i++)
  14.         {
  15.             if (odnaleziono == true)
  16.             {
  17.                 break;
  18.             }
  19.             if (tab[i] == szuk)
  20.             {
  21.                 plik_wyj << "odnaleziono" << std::endl;
  22.                 odnaleziono = true;
  23.                 break;
  24.             }
  25.         }
  26.    
  27. }
  28.  
  29. int main()
  30. {
  31.     std::vector<int> tab(200);
  32.     std::iota(tab.begin(), tab.end(), 1);
  33.     int x = 0;
  34.     for (int i = 0, j = 25; i < 200; i += 25, j += 25)
  35.     {
  36.         std::thread th(&search_tab, tab, i,j,100);
  37.         plik_wyj << "TH: " << th.get_id() << std::endl;
  38.         th.detach();
  39.     }
  40.     if (odnaleziono == false)
  41.         plik_wyj << "nie odnaleziono";
  42.  
  43.     std::cin.ignore(20);
  44. }
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