-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRef.cpp
More file actions
71 lines (57 loc) · 1.64 KB
/
Ref.cpp
File metadata and controls
71 lines (57 loc) · 1.64 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* \file Ref.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
class Test
{
public:
static std::mutex outMutex;
Test() = default;
void out(const int no, const double value) const;
void test() const;
};
//-------------------------------------------------------------------------------------------------
std::mutex Test::outMutex;
//-------------------------------------------------------------------------------------------------
void
Test::out(
const int no,
const double value
) const
{
{
std::lock_guard<std::mutex> locker(outMutex);
std::cout << "<- " << no << " -- " << value << std::endl;
}
// std::this_thread::sleep_for( std::chrono::seconds(1) );
}
//-------------------------------------------------------------------------------------------------
void
Test::test() const
{
const double w[2] {10.0, 20.0};
std::cout << "-> " << 0 << " -- " << w[0] << std::endl;
std::cout << "-> " << 1 << " -- " << w[1] << std::endl;
std::future<void> f1 = std::async(&Test::out, this, 0, std::ref(w[0]));
std::future<void> f2 = std::async(&Test::out, this, 1, std::ref(w[1]));
f1.get();
f2.get();
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
Test t;
t.test();
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
-> 0 -- 10
-> 1 -- 20
<- 0 -- 10
<- 1 -- 20
#endif