28#include <condition_variable>
45 std::queue<std::function<void()>> m_queue;
50 std::vector<std::thread> m_threads;
60 std::condition_variable m_condition;
70 unsigned int m_numThreads;
90 template<
class T,
class... Args>
91 std::future<
typename std::result_of<T(Args...)>::type>
enqueue(T&& t, Args&&... args)
93 using pkgdTask = std::packaged_task<
typename std::result_of<T(Args...)>::type()>;
95 std::shared_ptr<pkgdTask> task = std::make_shared<pkgdTask>(std::bind(std::forward<T>(t), std::forward<Args>(args)...));
96 auto result = task->get_future();
99 m_queue.emplace([task]() { (*task)(); });
102 m_condition.notify_one();
117 void threadFunction();
The main header file of the library defining the namespace and basic data types.
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition Audaspace.h:119
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition Audaspace.h:116
#define AUD_API
Used for exporting symbols in the shared library.
Definition Audaspace.h:93
This represents pool of threads.
Definition ThreadPool.h:40
std::future< typename std::result_of< T(Args...)>::type > enqueue(T &&t, Args &&... args)
Enqueues a new task for the threads to realize.
Definition ThreadPool.h:91
ThreadPool(unsigned int count)
Creates a new ThreadPool object.
unsigned int getNumOfThreads()
Retrieves the number of threads of the pool.