-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (79 loc) · 2.91 KB
/
main.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <ostream>
#include <thread>
#include "vector.hpp"
#include "lifetime.hpp"
#include "ringbuffer.hpp"
#include "threadpool.hpp"
using namespace dbstd;
void vectorTesting() {
Vector<int> intVec{2};
intVec.push_back(4);
intVec.push_back(2);
intVec.emplace_back(1);
Vector<Lifetime> lfVec;
lfVec.push_back(Lifetime{"moved lf"});
const Lifetime toCopy{"copied lf"};
lfVec.push_back(toCopy);
lfVec.reserve(3);
std::cout << "\nIn place construction*****\n";
lfVec.emplace_back("emplaced");
std::cout << "\nfirst vec contents************\n";
std::cout << lfVec[0] << '\n';
std::cout << lfVec[1] << '\n';
std::cout << lfVec[2] << '\n';
std::cout << "**************************\n\n";
Vector<Lifetime> copyConstructed{lfVec};
std::cout << "\ncopy constructed contents************\n";
std::cout << copyConstructed[0] << '\n';
std::cout << copyConstructed[1] << '\n';
std::cout << "**************************\n\n";
Vector<Lifetime> moveConstructed{std::move(lfVec)};
std::cout << "\nmove constructed contents************\n";
std::cout << moveConstructed[0] << '\n';
std::cout << moveConstructed[1] << '\n';
std::cout << "**************************\n\n";
copyConstructed = moveConstructed;
std::cout << "\ncopy assigned contents************\n";
std::cout << copyConstructed[0] << '\n';
std::cout << copyConstructed[1] << '\n';
std::cout << "**************************\n\n";
moveConstructed = std::move(copyConstructed);
std::cout << "\nmove assigned contents************\n";
std::cout << moveConstructed[0] << '\n';
std::cout << moveConstructed[1] << '\n';
std::cout << "**************************\n\n";
}
void dynamicRingBufferTesting() {
RingBuffer<Lifetime> rbuf(2);
rbuf.enqueue("first");
rbuf.enqueue("second");
auto first = rbuf.dequeue_and_get();
// NOLINTBEGIN(bugprone-unchecked-optional-access)
std::cout << "first: " << *first << '\n';
std::cout << "second: " << rbuf.front() << '\n';
rbuf.enqueue("third");
std::cout << "failed enqueue: " << (rbuf.enqueue("failed") ? "success" : "fail") << '\n';
std::cout << "second: " << rbuf.front() << '\n';
std::cout << "size of two: " << rbuf.size() << '\n';
rbuf.dequeue();
auto third = *rbuf.dequeue_and_get();
std::cout << "third: " << third << '\n';
// NOLINTEND(bugprone-unchecked-optional-access)
std::cout << "empty at end: " << (rbuf.empty() ? "true" : "false") << '\n';
}
int main() {
// vectorTesting();
// dynamicRingBufferTesting();
SP_ThreadPool tp(100, 8);
tp.start();
for (int i = 0; i < 100; i++) {
tp.enqueueJob([&i]() {
for (int ii = 0; ii < 100000; ii++) {}
std::cout << "done with " << i << std::endl;
});
}
tp.stop();
// std::this_thread::sleep_for(std::chrono::nanoseconds(100000));
return 0;
}