aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_non_blocking_thread_pool.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2016-12-09 13:05:14 -0800
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2016-12-09 13:05:14 -0800
commit2f5b7a199b9cecc9649a1ebec19fc214353b1422 (patch)
tree57918e980e646174b4b1e75f3506d29228319332 /unsupported/test/cxx11_non_blocking_thread_pool.cpp
parent3d59a477201d4d4f34b4332fda699c21387cf726 (diff)
Reworked the threadpool cancellation mechanism to not depend on pthread_cancel since it turns out that pthread_cancel doesn't work properly on numerous platforms.
Diffstat (limited to 'unsupported/test/cxx11_non_blocking_thread_pool.cpp')
-rw-r--r--unsupported/test/cxx11_non_blocking_thread_pool.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/unsupported/test/cxx11_non_blocking_thread_pool.cpp b/unsupported/test/cxx11_non_blocking_thread_pool.cpp
index fe30551ce..80d0ee080 100644
--- a/unsupported/test/cxx11_non_blocking_thread_pool.cpp
+++ b/unsupported/test/cxx11_non_blocking_thread_pool.cpp
@@ -104,23 +104,15 @@ static void test_parallelism()
static void test_cancel()
{
- NonBlockingThreadPool tp(4);
+ NonBlockingThreadPool tp(2);
-#ifdef EIGEN_SUPPORTS_THREAD_CANCELLATION
- std::cout << "Thread cancellation is supported on this platform" << std::endl;
-
- // Put 2 threads to sleep for much longer than the default test timeout.
- tp.Schedule([]() { sleep(3600); } );
- tp.Schedule([]() { sleep(3600 * 24); } );
-#else
- std::cout << "Thread cancellation is a no-op on this platform" << std::endl;
-
- // Make 2 threads sleep for a short period of time
- tp.Schedule([]() { sleep(1); } );
- tp.Schedule([]() { sleep(2); } );
-#endif
+ // Schedule a large number of closure that each sleeps for one second. This
+ // will keep the thread pool busy for much longer than the default test timeout.
+ for (int i = 0; i < 1000; ++i) {
+ tp.Schedule([]() { sleep(2); });
+ }
- // Call cancel:
+ // Cancel the processing of all the closures that are still pending.
tp.Cancel();
}