11 #define EIGEN_USE_THREADS 13 #include <Eigen/CXX11/ThreadPool> 18 #ifdef EIGEN_COMP_MSVC_STRICT 50 int val = val_.load(std::memory_order_relaxed);
54 if (val == kQueueSize)
return false;
55 if (val_.compare_exchange_weak(val, val + 1, std::memory_order_relaxed))
61 int val = val_.load(std::memory_order_relaxed);
65 if (val == 0)
return false;
66 if (val_.compare_exchange_weak(val, val - 1, std::memory_order_relaxed))
71 bool Empty() {
return val_.load(std::memory_order_relaxed) == 0; }
81 const int kThreads = std::thread::hardware_concurrency();
82 static const int kEvents = 1 << 16;
83 static const int kQueues = 10;
90 std::vector<std::unique_ptr<std::thread>> producers;
91 for (
int i = 0;
i < kThreads;
i++) {
92 producers.emplace_back(
new std::thread([&ec, &queues]() {
93 unsigned int rnd =
static_cast<unsigned int>(std::hash<std::thread::id>()(std::this_thread::get_id()));
94 for (
int j = 0;
j < kEvents;
j++) {
96 if (queues[idx].
Push()) {
106 std::vector<std::unique_ptr<std::thread>> consumers;
107 for (
int i = 0;
i < kThreads;
i++) {
108 consumers.emplace_back(
new std::thread([&ec, &queues, &waiters,
i]() {
110 unsigned int rnd =
static_cast<unsigned int>(std::hash<std::thread::id>()(std::this_thread::get_id()));
111 for (
int j = 0;
j < kEvents;
j++) {
113 if (queues[idx].
Pop())
continue;
117 for (
int q = 0;
q < kQueues;
q++) {
132 for (
int i = 0;
i < kThreads;
i++) {
133 producers[
i]->join();
134 consumers[
i]->join();
EIGEN_DECLARE_TEST(cxx11_eventcount)
#define VERIFY_IS_EQUAL(a, b)
#define EIGEN_THREAD_YIELD()
static const int kQueueSize
EIGEN_DEVICE_FUNC const Scalar & q
#define CALL_SUBTEST(FUNC)
int rand_reentrant(unsigned int *s)
static void test_basic_eventcount()
void Notify(bool notifyAll)
#define EIGEN_UNUSED_VARIABLE(var)
void CommitWait(Waiter *w)
static void test_stress_eventcount()