mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Merged eigen/eigen into default
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
|
||||
#define EIGEN_USE_THREADS
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
#include "Eigen/CXX11/ThreadPool"
|
||||
#include "Eigen/CXX11/Tensor"
|
||||
|
||||
static void test_create_destroy_empty_pool()
|
||||
{
|
||||
@@ -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;
|
||||
// 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([]() { EIGEN_SLEEP(2000); });
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// Call cancel:
|
||||
// Cancel the processing of all the closures that are still pending.
|
||||
tp.Cancel();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,6 @@
|
||||
#include "main.h"
|
||||
#include <Eigen/CXX11/Tensor>
|
||||
|
||||
#if EIGEN_OS_WIN || EIGEN_OS_WIN64
|
||||
#include <windows.h>
|
||||
void sleep(int seconds) {
|
||||
Sleep(seconds*1000);
|
||||
}
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -40,7 +31,7 @@ static void test_notification_single()
|
||||
Eigen::Notification n;
|
||||
std::function<void()> func = std::bind(&WaitAndAdd, &n, &counter);
|
||||
thread_pool.Schedule(func);
|
||||
sleep(1);
|
||||
EIGEN_SLEEP(1000);
|
||||
|
||||
// The thread should be waiting for the notification.
|
||||
VERIFY_IS_EQUAL(counter, 0);
|
||||
@@ -48,7 +39,7 @@ static void test_notification_single()
|
||||
// Unblock the thread
|
||||
n.Notify();
|
||||
|
||||
sleep(1);
|
||||
EIGEN_SLEEP(1000);
|
||||
|
||||
// Verify the counter has been incremented
|
||||
VERIFY_IS_EQUAL(counter, 1);
|
||||
@@ -67,10 +58,10 @@ static void test_notification_multiple()
|
||||
thread_pool.Schedule(func);
|
||||
thread_pool.Schedule(func);
|
||||
thread_pool.Schedule(func);
|
||||
sleep(1);
|
||||
EIGEN_SLEEP(1000);
|
||||
VERIFY_IS_EQUAL(counter, 0);
|
||||
n.Notify();
|
||||
sleep(1);
|
||||
EIGEN_SLEEP(1000);
|
||||
VERIFY_IS_EQUAL(counter, 4);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user