-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsome_thread.cpp
More file actions
45 lines (44 loc) · 825 Bytes
/
Copy pathsome_thread.cpp
File metadata and controls
45 lines (44 loc) · 825 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
#include <thread>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
void do_something(int &i)
{
std::cout<<i<<std::endl;
}
struct func
{
int &i;
func(int &i_):i(i_){};
void operator()()
{
for(unsigned j = 0; j < 1000000;++j)
{
do_something(i);
sleep(3);
}
}
};
void oops()
{
int some_local_state = 0;
func myFunc(some_local_state);
func myFunc1(some_local_state);
std::thread myThread(myFunc);
std::thread myThread1(myFunc1);
myThread.detach();
myThread1.detach();
// sleep(1);
}
int main()
{
// oops();
std::cout<<"sss"<<std::endl;
int a;
int some_local_state = 0;
func myFunc(some_local_state);
std::thread myThread(myFunc);
myThread.detach();
std::cin>>a;
return 0;
}