cxx11_tensor_notification.cpp File Reference
#include <atomic>
#include <stdlib.h>
#include "main.h"
#include <Eigen/CXX11/Tensor>

Macros

#define EIGEN_USE_THREADS
 

Functions

static void test_notification_single ()
 
static void test_notification_multiple ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_notification)
 

Macro Definition Documentation

◆ EIGEN_USE_THREADS

#define EIGEN_USE_THREADS

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_notification  )
64  {
67 }
static void test_notification_multiple()
Definition: cxx11_tensor_notification.cpp:44
static void test_notification_single()
Definition: cxx11_tensor_notification.cpp:18
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, test_notification_multiple(), and test_notification_single().

◆ test_notification_multiple()

static void test_notification_multiple ( )
static
44  {
45  ThreadPool thread_pool(1);
46 
47  std::atomic<int> counter(0);
49  auto func = [&n, &counter]() {
50  n.Wait();
51  ++counter;
52  };
53  thread_pool.Schedule(func);
54  thread_pool.Schedule(func);
55  thread_pool.Schedule(func);
56  thread_pool.Schedule(func);
57  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
58  VERIFY_IS_EQUAL(counter, 0);
59  n.Notify();
60  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
61  VERIFY_IS_EQUAL(counter, 4);
62 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Definition: NonBlockingThreadPool.h:19
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
Definition: Barrier.h:64
Definition: benchGeometry.cpp:21

References n, Eigen::ThreadPoolTempl< Environment >::Schedule(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_notification_single()

static void test_notification_single ( )
static
18  {
19  ThreadPool thread_pool(1);
20 
21  std::atomic<int> counter(0);
23  auto func = [&n, &counter]() {
24  n.Wait();
25  ++counter;
26  };
27  thread_pool.Schedule(func);
28  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
29 
30  // The thread should be waiting for the notification.
31  VERIFY_IS_EQUAL(counter, 0);
32 
33  // Unblock the thread
34  n.Notify();
35 
36  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
37 
38  // Verify the counter has been incremented
39  VERIFY_IS_EQUAL(counter, 1);
40 }

References n, Eigen::ThreadPoolTempl< Environment >::Schedule(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().