-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_thread.cpp
More file actions
44 lines (40 loc) · 869 Bytes
/
cpp_thread.cpp
File metadata and controls
44 lines (40 loc) · 869 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
#include<iostream>
#include<thread>
using namespace std;
void foo(int xyz)
{
cout<<"thread create using function pointer ("<<xyz<<")"<<endl;
}
// A callable object
class thread_obj {
public:
thread_obj()
{
cout << "thread_obj()"<<endl;
}
thread_obj(const thread_obj & x)
{
cout << "CP thread_obj()"<<endl;
}
void operator()(int x)
{
for (int i = 0; i < x; i++)
cout << "Thread using function"
" object as callable "<<i<<endl;
}
~thread_obj()
{
cout << "~ thread_obj()"<<endl;
}
};
int main()
{
auto fun = [] (int z){cout<<"thread created using functor"<<endl;};
//thread th1(foo, 122);
//thread th2(fun, 445);
thread th3(thread_obj(),2);
//th1.join();
//th2.join();
th3.join();
//thread_obj();
}