#include <atomic>
#include "gtest/gtest.h"
#include "misc_language.h"
#include "common/threadpool.h"
Go to the source code of this file.
|
| | TEST (threadpool, wait_nothing) |
| | TEST (threadpool, wait_waits) |
| | TEST (threadpool, one_thread) |
| | TEST (threadpool, many_threads) |
| | TEST (threadpool, reentrency) |
| | TEST (threadpool, reentrancy) |
| | TEST (threadpool, leaf_throws) |
| | TEST (threadpool, leaf_reentrancy) |
◆ TEST() [1/8]
| TEST |
( |
threadpool | , |
|
|
leaf_reentrancy | ) |
Definition at line 127 of file threadpool.cpp.
128{
131
132 std::atomic<int> counter(0);
133 for (int i = 0; i < 1000; ++i)
134 {
135 tpool->submit(&waiter, [&](){
137 for (int j = 0; j < 500; ++j)
138 {
139 tpool->submit(&waiter, [&](){ ++counter; }, true);
140 }
141 waiter.
wait(tpool.get());
142 });
143 }
144 waiter.
wait(tpool.get());
146}
#define ASSERT_EQ(val1, val2)
◆ TEST() [2/8]
| TEST |
( |
threadpool | , |
|
|
leaf_throws | ) |
Definition at line 112 of file threadpool.cpp.
113{
116
117 bool thrown = false, executed = false;
118 tpool->submit(&waiter, [&](){
119 try { tpool->submit(&waiter, [&](){ executed = true; }); }
120 catch(const std::exception &e) { thrown = true; }
121 }, true);
122 waiter.
wait(tpool.get());
125}
#define ASSERT_FALSE(condition)
#define ASSERT_TRUE(condition)
◆ TEST() [3/8]
| TEST |
( |
threadpool | , |
|
|
many_threads | ) |
Definition at line 66 of file threadpool.cpp.
67{
70
71 std::atomic<unsigned int> counter(0);
72 for (size_t n = 0; n < 4096; ++n)
73 {
74 tpool->submit(&waiter, [&counter](){++counter;});
75 }
76 waiter.
wait(tpool.get());
78}
◆ TEST() [4/8]
| TEST |
( |
threadpool | , |
|
|
one_thread | ) |
Definition at line 52 of file threadpool.cpp.
53{
56
57 std::atomic<unsigned int> counter(0);
58 for (size_t n = 0; n < 4096; ++n)
59 {
60 tpool->submit(&waiter, [&counter](){++counter;});
61 }
62 waiter.
wait(tpool.get());
64}
◆ TEST() [5/8]
| TEST |
( |
threadpool | , |
|
|
reentrancy | ) |
Definition at line 102 of file threadpool.cpp.
103{
106
108 waiter.
wait(tpool.get());
110}
unsigned __int64 uint64_t
◆ TEST() [6/8]
| TEST |
( |
threadpool | , |
|
|
reentrency | ) |
◆ TEST() [7/8]
| TEST |
( |
threadpool | , |
|
|
wait_nothing | ) |
◆ TEST() [8/8]
| TEST |
( |
threadpool | , |
|
|
wait_waits | ) |
Definition at line 41 of file threadpool.cpp.
42{
45 std::atomic<bool> b(false);
48 waiter.
wait(tpool.get());
50}