-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
86 lines (78 loc) · 1.48 KB
/
test.cpp
File metadata and controls
86 lines (78 loc) · 1.48 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <windows.h>
#include <string>
#include <chrono>
#include "ThreadPool.h"
#include "ThreadPoolLockFree.h"
int func1(int i)
{
std::string str = "Func1: " + std::to_string(i) + "\n";
std::cout << str;
return i;
}
class Test
{
public:
int Test1(int i)
{
std::string str = "Test1: " + std::to_string(i) + "\n";
std::cout << str;
return i;
}
private:
ThreadPool pool;
public:
Test(){}
void Run()
{
for (int i = 0; i < 3; i++)
{
pool.PushThread(&Test::Test1, this, i);
}
for (int i = 0; i < 3; i++)
{
pool.PushThread(func1, i);
}
}
};
LockFreeQueue<int> myQueue;
void funcPush(int i)
{
myQueue.push(i);
}
void funcPop()
{
std::shared_ptr<int> pN = myQueue.pop();
if (pN != nullptr)
{
std::string str = std::to_string(*pN.get()) + "\n";
std::cout << str;
}
else
{
//std::cout << "Empty\n";
}
}
int main()
{
ThreadPoolLockFree pool;
for (size_t i = 0; i < 100; i++)
{
pool.PushThread(funcPush, i);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
while (myQueue.size()!=0)
{
pool.PushThread(funcPop);
}
for (size_t i = 100; i < 10000; i++)
{
pool.PushThread(funcPush, i);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
while (myQueue.size()!=0)
{
pool.PushThread(funcPop);
}
return 0;
}