11 #define EIGEN_USE_THREADS 14 #include <Eigen/CXX11/ThreadPool> 20 #ifdef EIGEN_COMP_MSVC_STRICT 33 VERIFY_IS_EQUAL(0u, q.Size());
34 VERIFY_IS_EQUAL(0, q.PopFront());
35 std::vector<int> stolen;
36 VERIFY_IS_EQUAL(0u, q.PopBackHalf(&stolen));
37 VERIFY_IS_EQUAL(0u, stolen.size());
39 VERIFY_IS_EQUAL(0, q.PushFront(1));
40 VERIFY_IS_EQUAL(1u, q.Size());
41 VERIFY_IS_EQUAL(1, q.PopFront());
42 VERIFY_IS_EQUAL(0u, q.Size());
44 VERIFY_IS_EQUAL(0, q.PushFront(2));
45 VERIFY_IS_EQUAL(1u, q.Size());
46 VERIFY_IS_EQUAL(0, q.PushFront(3));
47 VERIFY_IS_EQUAL(2u, q.Size());
48 VERIFY_IS_EQUAL(0, q.PushFront(4));
49 VERIFY_IS_EQUAL(3u, q.Size());
50 VERIFY_IS_EQUAL(0, q.PushFront(5));
51 VERIFY_IS_EQUAL(4u, q.Size());
52 VERIFY_IS_EQUAL(6, q.PushFront(6));
53 VERIFY_IS_EQUAL(4u, q.Size());
54 VERIFY_IS_EQUAL(5, q.PopFront());
55 VERIFY_IS_EQUAL(3u, q.Size());
56 VERIFY_IS_EQUAL(4, q.PopFront());
57 VERIFY_IS_EQUAL(2u, q.Size());
58 VERIFY_IS_EQUAL(3, q.PopFront());
59 VERIFY_IS_EQUAL(1u, q.Size());
60 VERIFY_IS_EQUAL(2, q.PopFront());
61 VERIFY_IS_EQUAL(0u, q.Size());
62 VERIFY_IS_EQUAL(0, q.PopFront());
64 VERIFY_IS_EQUAL(0, q.PushBack(7));
65 VERIFY_IS_EQUAL(1u, q.Size());
66 VERIFY_IS_EQUAL(1u, q.PopBackHalf(&stolen));
67 VERIFY_IS_EQUAL(1u, stolen.size());
68 VERIFY_IS_EQUAL(7, stolen[0]);
69 VERIFY_IS_EQUAL(0u, q.Size());
72 VERIFY_IS_EQUAL(0, q.PushBack(8));
73 VERIFY_IS_EQUAL(1u, q.Size());
74 VERIFY_IS_EQUAL(0, q.PushBack(9));
75 VERIFY_IS_EQUAL(2u, q.Size());
76 VERIFY_IS_EQUAL(0, q.PushBack(10));
77 VERIFY_IS_EQUAL(3u, q.Size());
78 VERIFY_IS_EQUAL(0, q.PushBack(11));
79 VERIFY_IS_EQUAL(4u, q.Size());
80 VERIFY_IS_EQUAL(12, q.PushBack(12));
81 VERIFY_IS_EQUAL(4u, q.Size());
83 VERIFY_IS_EQUAL(2u, q.PopBackHalf(&stolen));
84 VERIFY_IS_EQUAL(2u, stolen.size());
85 VERIFY_IS_EQUAL(10, stolen[0]);
86 VERIFY_IS_EQUAL(11, stolen[1]);
87 VERIFY_IS_EQUAL(2u, q.Size());
89 VERIFY_IS_EQUAL(1u, q.PopBackHalf(&stolen));
90 VERIFY_IS_EQUAL(1u, stolen.size());
91 VERIFY_IS_EQUAL(9, stolen[0]);
92 VERIFY_IS_EQUAL(1u, q.Size());
94 VERIFY_IS_EQUAL(1u, q.PopBackHalf(&stolen));
95 VERIFY_IS_EQUAL(1u, stolen.size());
96 VERIFY_IS_EQUAL(8, stolen[0]);
98 VERIFY_IS_EQUAL(0u, q.PopBackHalf(&stolen));
99 VERIFY_IS_EQUAL(0u, stolen.size());
102 VERIFY_IS_EQUAL(0u, q.Size());
103 VERIFY_IS_EQUAL(0, q.PushFront(1));
104 VERIFY_IS_EQUAL(0, q.PushFront(2));
105 VERIFY_IS_EQUAL(0, q.PushFront(3));
106 VERIFY_IS_EQUAL(1, q.PopBack());
107 VERIFY_IS_EQUAL(2, q.PopBack());
108 VERIFY_IS_EQUAL(3, q.PopBack());
110 VERIFY_IS_EQUAL(0u, q.Size());
124 std::atomic<bool> done(
false);
125 std::thread mutator([&q, &done]() {
127 std::vector<int> stolen;
128 for (
int i = 0; i < 1 << 18; i++) {
130 VERIFY_IS_EQUAL(0, q.PushFront(1));
132 VERIFY_IS_EQUAL(0, q.PushBack(1));
134 VERIFY_IS_EQUAL(1, q.PopFront());
137 if (q.PopBackHalf(&stolen) == 1) {
141 VERIFY_IS_EQUAL(0u, stolen.size());
153 VERIFY_IS_EQUAL(1, q.PopFront());
162 static const int kEvents = 1 << 18;
164 std::atomic<int> total(0);
165 std::vector<std::unique_ptr<std::thread>> threads;
166 threads.emplace_back(
new std::thread([&q, &total]() {
170 while (pushed < kEvents || popped < kEvents) {
171 if (pushed < kEvents) {
172 if (q.PushFront(pushed) == 0) {
177 if (popped < kEvents) {
178 int v = q.PopFront();
187 for (
int i = 0; i < 2; i++) {
188 threads.emplace_back(
new std::thread([&q, &total]() {
190 for (
int j = 1; j < kEvents; j++) {
191 if (q.PushBack(j) == 0) {
200 threads.emplace_back(
new std::thread([&q, &total]() {
202 std::vector<int> stolen;
203 for (
int j = 1; j < kEvents;) {
204 if (q.PopBackHalf(&stolen) == 0) {
208 while (stolen.size() && j < kEvents) {
209 int v = stolen.back();
211 VERIFY_IS_NOT_EQUAL(v, 0);
216 while (stolen.size()) {
217 int v = stolen.back();
219 VERIFY_IS_NOT_EQUAL(v, 0);
225 for (
size_t i = 0; i < threads.size(); i++) threads[i]->join();
227 VERIFY(total.load() == 0);
void test_cxx11_runqueue()
void test_basic_runqueue()
int rand_reentrant(unsigned int *s)
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
#define EIGEN_THREAD_YIELD()
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
EIGEN_DEVICE_FUNC const Scalar & q
void test_stress_runqueue()
void test_empty_runqueue()
#define EIGEN_UNUSED_VARIABLE(var)