-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (36 loc) · 794 Bytes
/
Copy pathmain.cpp
File metadata and controls
44 lines (36 loc) · 794 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>
#include"lock-free-stack.h"
LFStack<int> stack;
bool start = false;
void fun(int num) {
ThreadEpoch<int> epoch;
while(!start);
for(int i = 0; i < 5; ++i) {
stack.push(num, epoch);
}
}
int main() {
std::vector<std::thread> array;
for(int i = 0; i < 100; ++i) {
array.push_back(std::thread(fun, i + 1));
}
ThreadEpoch<int> epoch;
start = true;
stack.search(5, epoch);
for(auto& thr : array) {
thr.join();
}
/*
stack.for_each([](int i) {
std::cout << i << ' ';
});
std::cout << std::endl;
*/
while(!stack.empty()) {
auto ptr = stack.pop(epoch);
std::cout << *ptr << ' ';
}
std::cout << std::endl;
return 0;
}