-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.cpp
More file actions
67 lines (54 loc) · 1.26 KB
/
base.cpp
File metadata and controls
67 lines (54 loc) · 1.26 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
#include <iostream>
#include <algorithm>
#include <iterator>
#include <set>
#include <utility>
#include "cppstyle.h"
// #include "templates.h"
#include <chrono>
#include <thread>
#include <mutex>
std::mutex g_lock;
void threadFunction()
{
g_lock.lock();
std::cout << "entered thread " << std::this_thread::get_id() << std::endl;
// std::this_thread::sleep_for(std::chrono::seconds(rand()%10));
std::this_thread::sleep_for(std::chrono::seconds(2));
std::cout << "leaving thread " << std::this_thread::get_id() << std::endl;
g_lock.unlock();
}
void hello()
{
std::cout<<"Hello Concurrent World\n";
}
int main(int argc, char * argv[])
{
the_test();
ClassA* a;
// ClassB* b;
ClassC* c;
try
{
a = new ClassA;
c = new ClassC;
}
catch(std::bad_alloc& exc)
{
std::cout << "allocate error" << std::endl;
return 1;
}
a->printname();
c->printname();
// srand((unsigned int)time(0));
std::thread t1(threadFunction);
std::thread t2(threadFunction);
t1.join();
t2.join();
// std::cout << "please enter int values and pass Ctrl+D" << std::endl;
// simple_sorting();
std::cout << "\nfinish"<< std::endl;
delete a;
delete c;
return 0;
}