Mantid
Loading...
Searching...
No Matches
ThreadPool.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidKernel/DllConfig.h"
11#include <vector>
12
13// Forward declares
14
15namespace Poco {
16class Thread;
17}
18
19namespace Mantid {
20namespace Kernel {
21class ProgressBase;
22class Task;
23class ThreadPoolRunnable;
24
36class MANTID_KERNEL_DLL ThreadPool final {
37public:
38 ThreadPool(ThreadScheduler *scheduler = new ThreadSchedulerFIFO(), size_t numThreads = 0,
39 ProgressBase *prog = nullptr);
40
42
43 void start(double waitSec = 0.0);
44
45 void schedule(const std::shared_ptr<Task> &task, bool start = false);
46
47 void joinAll();
48
49 static size_t getNumPhysicalCores();
50
51protected:
54
56 std::unique_ptr<ThreadScheduler> m_scheduler;
57
59 std::vector<std::unique_ptr<Poco::Thread>> m_threads;
60
62 std::vector<std::unique_ptr<ThreadPoolRunnable>> m_runnables;
63
66
68 std::unique_ptr<ProgressBase> m_prog;
69
70private:
71 // prohibit default copy constructor as it does not work
73 // prohibit asighnment as it does not work
75};
76
78//#ifdef _WIN32
79// // this breaks new namespace declaraion rules; need to find a better fix
80// template class MANTID_KERNEL_DLL
81// Mantid::Kernel::SingletonHolder<ThreadPoolImpl>;
82//#endif /* _WIN32 */
83// typedef Mantid::Kernel::SingletonHolder<ThreadPoolImpl>
84// ThreadPool;
85
86} // namespace Kernel
87} // namespace Mantid
A Thread Pool implementation that keeps a certain number of threads running (normally,...
Definition: ThreadPool.h:36
ThreadPool & operator=(const ThreadPool &other)
std::vector< std::unique_ptr< Poco::Thread > > m_threads
Vector with all the threads that are started.
Definition: ThreadPool.h:59
size_t m_numThreads
Number of cores used.
Definition: ThreadPool.h:53
bool m_started
Have the threads started?
Definition: ThreadPool.h:65
std::vector< std::unique_ptr< ThreadPoolRunnable > > m_runnables
Vector of the POCO-required classes to actually run in a thread.
Definition: ThreadPool.h:62
std::unique_ptr< ProgressBase > m_prog
Progress reporter.
Definition: ThreadPool.h:68
ThreadPool(const ThreadPool &)
std::unique_ptr< ThreadScheduler > m_scheduler
The ThreadScheduler instance taking care of task scheduling.
Definition: ThreadPool.h:56
A First-In-First-Out Thread Scheduler.
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30