From ebf04fb3e8dcab201d56fd1e3df4bf9c2bdaefc5 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Fri, 8 Nov 2019 17:44:50 -0800 Subject: Fix data race in css11_tensor_notification test. --- unsupported/test/cxx11_tensor_notification.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'unsupported/test') diff --git a/unsupported/test/cxx11_tensor_notification.cpp b/unsupported/test/cxx11_tensor_notification.cpp index f63fee013..2bade8dc7 100644 --- a/unsupported/test/cxx11_tensor_notification.cpp +++ b/unsupported/test/cxx11_tensor_notification.cpp @@ -9,27 +9,19 @@ #define EIGEN_USE_THREADS +#include + #include #include "main.h" #include - -namespace { - -void WaitAndAdd(Eigen::Notification* n, int* counter) { - n->Wait(); - *counter = *counter + 1; -} - -} // namespace - static void test_notification_single() { ThreadPool thread_pool(1); - int counter = 0; + std::atomic counter(0); Eigen::Notification n; - std::function func = std::bind(&WaitAndAdd, &n, &counter); + auto func = [&n, &counter](){ n.Wait(); ++counter;}; thread_pool.Schedule(func); EIGEN_SLEEP(1000); @@ -51,9 +43,9 @@ static void test_notification_multiple() { ThreadPool thread_pool(1); - int counter = 0; + std::atomic counter(0); Eigen::Notification n; - std::function func = std::bind(&WaitAndAdd, &n, &counter); + auto func = [&n, &counter](){ n.Wait(); ++counter;}; thread_pool.Schedule(func); thread_pool.Schedule(func); thread_pool.Schedule(func); -- cgit v1.2.3