forked from PhysicsX/ExampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnonAutoDuration.cpp
More file actions
51 lines (41 loc) · 779 Bytes
/
nonAutoDuration.cpp
File metadata and controls
51 lines (41 loc) · 779 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <thread>
// g++ nonAutoDuration.cpp -o example -lpthread
// valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./example
class Example
{
public:
int a = 1;
};
void foo()
{
static Example ex;
ex.a = 1;
std::thread t([&ex]()mutable{
std::cout<<ex.a<<"\n";
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
ex.a = 4;
std::cout<<ex.a<<"\n";
});
t.detach();
//ex.a = 3;
}
int main()
{
foo();
/*
Example ex;
ex.a = 2;
std::thread t([&ex]()mutable{
std::cout<<ex.a<<std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
ex.a = 4;
std::cout<<ex.a<<std::endl;
});
t.detach();
*/
std::cout<<"here first\n"<<std::endl;
while(1);
//ex.a = 3;
return 0;
}