diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2016-04-19 12:57:39 -0700 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2016-04-19 12:57:39 -0700 |
commit | f953c607058efd7c3508e888ac4bf2c526336b87 (patch) | |
tree | c89c8ac5f7726f796da5613e2fcb342467bc7d22 /unsupported/test/cxx11_eventcount.cpp | |
parent | 50968a0a3ed2686b25f6df1687f4cf7fc6b66da1 (diff) |
Fixed 2 recent regression tests
Diffstat (limited to 'unsupported/test/cxx11_eventcount.cpp')
-rw-r--r-- | unsupported/test/cxx11_eventcount.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/unsupported/test/cxx11_eventcount.cpp b/unsupported/test/cxx11_eventcount.cpp index 59039dae9..898c4c278 100644 --- a/unsupported/test/cxx11_eventcount.cpp +++ b/unsupported/test/cxx11_eventcount.cpp @@ -12,11 +12,14 @@ #include "main.h" #include <Eigen/CXX11/ThreadPool> +// Visual studio doesn't implement a rand_r() function since its +// implementation of rand() is already thread safe +int rand_reentrant(unsigned int* s) { #ifdef EIGEN_COMP_MSVC_STRICT -// Visual studio doesn't implementan rand_r() function since its -// implementation of rand()is already thread safe -int rand_r(unsigned int*) { return rand(); +#else + return rand_r(s); +endif } #endif @@ -85,15 +88,15 @@ static void test_stress_eventcount() std::vector<std::unique_ptr<std::thread>> producers; for (int i = 0; i < kThreads; i++) { producers.emplace_back(new std::thread([&ec, &queues]() { - unsigned rnd = std::hash<std::thread::id>()(std::this_thread::get_id()); - for (int i = 0; i < kEvents; i++) { - unsigned idx = rand_r(&rnd) % kQueues; + unsigned int rnd = static_cast<unsigned int>(std::hash<std::thread::id>()(std::this_thread::get_id())); + for (int j = 0; j < kEvents; j++) { + unsigned idx = rand_reentrant(&rnd) % kQueues; if (queues[idx].Push()) { ec.Notify(false); continue; } std::this_thread::yield(); - i--; + j--; } })); } @@ -102,11 +105,11 @@ static void test_stress_eventcount() for (int i = 0; i < kThreads; i++) { consumers.emplace_back(new std::thread([&ec, &queues, &waiters, i]() { EventCount::Waiter& w = waiters[i]; - unsigned rnd = std::hash<std::thread::id>()(std::this_thread::get_id()); - for (int i = 0; i < kEvents; i++) { - unsigned idx = rand_r(&rnd) % kQueues; + unsigned int rnd = static_cast<unsigned int>(std::hash<std::thread::id>()(std::this_thread::get_id())); + for (int j = 0; j < kEvents; k++) { + unsigned idx = rand_reentrant(&rnd) % kQueues; if (queues[idx].Pop()) continue; - i--; + j--; ec.Prewait(&w); bool empty = true; for (int q = 0; q < kQueues; q++) { |