87 template <
typename F,
typename... Args,
typename R =
typename std::result_of<F(Args...)>::type>
88 std::future<R>
submitJob(F&& f, Args&&... args);
94 template <
typename F,
typename R =
typename std::result_of<F()>::type>
101 template <
typename R>
108 template <
typename R>
115 template <
typename R>
122 template <
typename R>
164template <
typename F,
typename R>
167 auto job = std::make_shared<std::packaged_task<R()>>(std::forward<F>(f));
170 std::unique_lock<std::mutex> lock(
myMutex);
180 return job->get_future();
183template <
typename F,
typename... Args,
typename R>
186 auto job = std::make_shared<std::packaged_task<R()>>(std::bind(std::forward<F>(f), std::forward<Args>(args)...));
189 std::unique_lock<std::mutex> lock(
myMutex);
199 return job->get_future();
205 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
211 return f.wait_for(std::chrono::seconds(0));
217 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
223 return f.wait_for(std::chrono::seconds(0));
static std::future_status getSharedFutureStatus(std::shared_future< R > const &f)
Gets the status of a shared future.
Definition vreThreadPool.h:221
DtVreThreadPool(std::size_t threads)
Constructor that initializes the thread pool with a specified number of threads.
JobType getNextJob()
Gets the next job from the queue.
void resize(std::size_t nThreads)
Resizes the thread pool to a new number of threads.
static bool isFutureReady(std::future< R > const &f)
Checks if a future is ready (completed)
Definition vreThreadPool.h:203
std::vector< std::unique_ptr< std::thread > > myThreads
Collection of worker threads.
Definition vreThreadPool.h:145
std::function< void()> JobType
Function type for jobs to be executed by the thread pool.
Definition vreThreadPool.h:32
std::atomic< bool > myStop
Flag indicating if the thread pool should stop.
Definition vreThreadPool.h:151
DtVreThreadPool(const DtVreThreadPool &)=delete
Copy constructor (deleted)
DtVreThreadPool(DtVreThreadPool &&)=delete
Move constructor (deleted)
DtVreThreadPool & operator=(const DtVreThreadPool &)=delete
Copy assignment operator (deleted)
std::size_t threadCount() const
Returns the number of threads in the pool.
std::queue< JobType > myJobQueue
Queue of pending jobs.
Definition vreThreadPool.h:148
std::condition_variable myNotifier
Condition variable for notifying threads of new jobs.
Definition vreThreadPool.h:160
void shutdown(bool join=true)
Shuts down the thread pool.
void createThreads(std::size_t nThreads)
Creates worker threads for the pool.
~DtVreThreadPool()
Destructor that shuts down the thread pool.
static std::future_status getFutureStatus(std::future< R > const &f)
Gets the status of a future.
Definition vreThreadPool.h:209
std::size_t activeCount() const
Returns the number of currently active (working) threads.
DtVreThreadPool & operator=(DtVreThreadPool &&)=delete
Move assignment operator (deleted)
void emptyQueue()
Empties the job queue.
std::atomic< std::size_t > myActiveThreads
Counter for the number of active threads.
Definition vreThreadPool.h:154
static bool isSharedFutureReady(std::shared_future< R > const &f)
Checks if a shared future is ready (completed)
Definition vreThreadPool.h:215
std::future< R > submitJob(F &&f, Args &&... args)
Submits a job with arguments to the thread pool.
Definition vreThreadPool.h:184
std::mutex myMutex
Mutex for synchronizing access to the job queue.
Definition vreThreadPool.h:157
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
Include export definitions for this library.
Definition glsVreMessageUtil.h:49