Turi Create  4.0
turi::parallel_task_queue Class Reference

#include <core/parallel/thread_pool.hpp>

Public Member Functions

 parallel_task_queue (thread_pool &pool)
 
void launch (const boost::function< void(void)> &spawn_function, size_t virtual_threadid=size_t(-1))
 
void join ()
 
 ~parallel_task_queue ()
 

Detailed Description

This class adds a task queueing structure on top of a thread_pool, while providing the same interface as the thread_pool. Multiple parallel_task_queue objects can be associated with the same thread_pool and each parallel_task_queue instance has its own indepedendent task joining capability.

The parallel_task_queue also provides exception forwarding. exception throws within a thread of type const char* will be caught and forwarded to the join() function. If the call to join() is wrapped by a try-catch block, the exception will be caught safely and thread cleanup will be completed properly.

Usage:

queue.launch(...)
...
queue.join()

Definition at line 39 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ parallel_task_queue()

turi::parallel_task_queue::parallel_task_queue ( thread_pool pool)

Create a parallel_task_queue which is associated with a particular pool. All tasks used by the parallel task_queue will use the pool for its pool of threads.

◆ ~parallel_task_queue()

turi::parallel_task_queue::~parallel_task_queue ( )

Destructor. Waits for all tasks to complete.

Member Function Documentation

◆ join()

void turi::parallel_task_queue::join ( )

Waits for all tasks to complete. const char* exceptions thrown by threads are forwarded to the join() function. Once this function returns normally, the queue is empty.

Note that this function may not return if producers continually insert tasks through launch.

◆ launch()

void turi::parallel_task_queue::launch ( const boost::function< void(void)> &  spawn_function,
size_t  virtual_threadid = size_t(-1) 
)

Launch a single task into the thread pool which calls spawn_function.

If virtual_threadid is set, the target thread will appear to have thread ID equal to the requested thread ID.


The documentation for this class was generated from the following file: