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;
73 ThreadPool(
const ThreadPool&) =
delete;
74 ThreadPool& operator=(
const ThreadPool&) =
delete;
82 virtual ~ThreadPool();
90 template<
class T,
class... Args>
93 using pkgdTask = std::packaged_task<typename std::invoke_result<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
ThreadPool(unsigned int count)
Creates a new ThreadPool object.
auto enqueue(T &&t, Args &&... args)
Enqueues a new task for the threads to realize.
Definition ThreadPool.h:91
unsigned int getNumOfThreads()
Retrieves the number of threads of the pool.