-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht1.cpp
More file actions
34 lines (27 loc) · 794 Bytes
/
Copy patht1.cpp
File metadata and controls
34 lines (27 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// thread example
#include <iostream> // std::cout
#include <thread> // std::thread
#include <vector>
#include <string>
std::string foo()
{
std::string inp="";
std::cout<<"foo..."<<std::endl;
std::cin>>"presnij batona: ">> inp;
}
void bar(std::string& x)
{
std::cout<<"bar..."<<std::endl;
std::cout<<"foo wygenerowal: "<<x<<std::endl;
}
int main()
{
std::thread first(foo); // spawn new thread that calls foo()
std::thread second(bar, ); // spawn new thread that calls bar(0)
std::cout << "main, foo and bar now execute concurrently...\n";
// synchronize threads:
first.join(); // pauses until first finishes
second.join(); // pauses until second finishes
std::cout << "foo and bar completed.\n";
return 0;
}