Parallel

vtr_thread_pool

A generic thread pool for parallel task execution.

namespace vtr
class thread_pool

A thread pool for parallel task execution. It is a naive implementation which uses a queue for each thread and assigns tasks in a round robin fashion.

Example usage:

vtr::thread_pool pool(4);  // 4 threads
pool.schedule_work([]{
    // Task body
});
pool.wait_for_all();  // There's no API to wait for a single task

Public Functions

inline thread_pool(size_t thread_count)

Create a thread pool with thread_count threads.

template<typename F>
inline void schedule_work(F &&f)

Schedule a function to be executed on one of the threads.

inline void wait_for_all()

Wait until the work queue is empty. Note that functions are allowed to schedule new functions.