-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlqueue.cc
More file actions
43 lines (38 loc) · 740 Bytes
/
lqueue.cc
File metadata and controls
43 lines (38 loc) · 740 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
#include "lqueue.h"
#include <iostream>
#include <thread>
template <typename T>
::std::ostream& operator<<(::std::ostream& os, const std::pair<T, bool>& m) {
if (!m.second)
return os << "Nothing";
else
return os << "Just " << m.first;
}
void push(lqueue<int>* lq, int count)
{
for (int i = 0; i < count; i++)
lq->push(i);
}
void pop(lqueue<int>* lq, int count)
{
while (count) {
if (lq->pop().second)
--count;
}
}
int main()
{
lqueue<int> lq;
std::thread t0(push, &lq, 1000);
std::thread t1(push, &lq, 1000);
std::thread t2(push, &lq, 1000);
std::thread c0(pop, &lq, 1000);
std::thread c1(pop, &lq, 1000);
std::thread c2(pop, &lq, 1000);
t0.join();
t1.join();
t2.join();
c0.join();
c1.join();
c2.join();
}