8 std::cout <<
"hello from " <<
id <<
", function\n";
11 void aga(
int id,
int par) {
12 std::cout <<
"hello from " <<
id <<
", function with parameter " << par <<
'\n';
16 Third(
int v) { this->v =
v; std::cout <<
"Third ctor " << this->v <<
'\n'; }
17 Third(
Third && c) { this->
v = c.v; std::cout<<
"Third move ctor\n"; }
18 Third(
const Third & c) { this->
v = c.
v; std::cout<<
"Third copy ctor\n"; }
19 ~Third() { std::cout <<
"Third dtor\n"; }
23 void mmm(
int id,
const std::string & s) {
24 std::cout <<
"mmm function " <<
id <<
' ' << s <<
'\n';
28 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
29 std::cout <<
"hello from " <<
id <<
", function with parameter Third " << t.
v <<
'\n';
35 std::future<void> qw =
p.push(std::ref(
first));
41 Second(
const std::string & s) { std::cout <<
"Second ctor\n"; this->s = s; }
42 Second(Second && c) { std::cout <<
"Second move ctor\n"; s = std::move(c.s); }
43 Second(
const Second & c) { std::cout <<
"Second copy ctor\n"; this->s = c.s; };
44 ~Second() { std::cout <<
"Second dtor\n"; }
45 void operator()(
int id)
const {
46 std::cout <<
"hello from " <<
id <<
' ' << this->s <<
'\n';
50 } second(
", functor");
52 p.push(std::ref(second));
53 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
54 p.push(
const_cast<const Second &
>(second));
55 p.push(std::move(second));
57 p.push(Second(
", functor"));
62 p.push(
ugu, std::ref(t));
64 p.push(
ugu, std::move(t));
71 std::string s =
", lambda";
73 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
74 std::cout <<
"hello from " <<
id <<
' ' << s <<
'\n';
78 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
79 std::cout <<
"hello from " <<
id <<
' ' << s <<
'\n';
82 p.push(
mmm,
"worked");
86 std::cout <<
"poped function from the pool ";
93 std::string s2 =
"result";
94 auto f1 =
p.push([s2](
int){
99 std::cout <<
"returned " << f1.get() <<
'\n';
101 auto f2 =
p.push([](
int){
102 throw std::exception();
109 catch (std::exception & e) {
110 std::cout <<
"caught exception\n";
114 auto & th =
p.get_thread(0);