VTK  9.1.0
Public Member Functions | List of all members
vtkThreadedTaskQueue< R, Args > Class Template Reference

simple threaded task queue More...

#include <vtkThreadedTaskQueue.h>

Public Member Functions

 vtkThreadedTaskQueue (std::function< R(Args...)> worker, bool strict_ordering=true, int buffer_size=-1, int max_concurrent_tasks=-1)
 
 ~vtkThreadedTaskQueue ()
 
void Push (Args &&... args)
 Push arguments for the work.
 
bool Pop (R &result)
 Pop the last result.
 
bool TryPop (R &result)
 Attempt to pop without waiting.
 
bool IsEmpty () const
 Returns false if there's some result that may be popped right now or in the future.
 
void Flush ()
 Blocks till the queue becomes empty.
 

Detailed Description

template<typename R, typename... Args>
class vtkThreadedTaskQueue< R, Args >

simple threaded task queue

vtkThreadedTaskQueue provides a simple task queue that can use threads to execute individual tasks. It is intended for use applications such as data compression, encoding etc. where the task may be completed concurrently without blocking the main thread.

vtkThreadedTaskQueue's API is intended to called from the same main thread. The constructor defines the work (or task) to be performed. Push allows the caller to enqueue a task with specified input arguments. The call will return immediately without blocking. The task is enqueued and will be executed concurrently when resources become available. Pop will block until the result is available. To avoid waiting for results to be available, use TryPop.

The constructor allows mechanism to customize the queue. strict_ordering implies that results should be popped in the same order that tasks were pushed without dropping any task. If the caller is only concerned with obtaining the latest available result where intermediate results that take longer to compute may be dropped, then strict_ordering can be set to false.

max_concurrent_tasks controls how many threads are used to process tasks in the queue. Default is same as vtkMultiThreader::GetGlobalDefaultNumberOfThreads().

buffer_size indicates how many tasks may be queued for processing. Default is infinite size. If a positive number is provided, then pushing additional tasks will result in discarding of older tasks that haven't begun processing from the queue. Note, this does not impact tasks that may already be in progress. Also, if strict_ordering is true, this is ignored; the buffer_size will be set to unlimited.

Definition at line 74 of file vtkThreadedTaskQueue.h.

Constructor & Destructor Documentation

◆ vtkThreadedTaskQueue()

template<typename R , typename... Args>
vtkThreadedTaskQueue< R, Args >::vtkThreadedTaskQueue ( std::function< R(Args...)>  worker,
bool  strict_ordering = true,
int  buffer_size = -1,
int  max_concurrent_tasks = -1 
)

◆ ~vtkThreadedTaskQueue()

template<typename R , typename... Args>
vtkThreadedTaskQueue< R, Args >::~vtkThreadedTaskQueue ( )

Member Function Documentation

◆ Push()

template<typename R , typename... Args>
void vtkThreadedTaskQueue< R, Args >::Push ( Args &&...  args)

Push arguments for the work.

◆ Pop()

template<typename R , typename... Args>
bool vtkThreadedTaskQueue< R, Args >::Pop ( R &  result)

Pop the last result.

Returns true on success. May fail if called on an empty queue. This will wait for result to be available.

◆ TryPop()

template<typename R , typename... Args>
bool vtkThreadedTaskQueue< R, Args >::TryPop ( R &  result)

Attempt to pop without waiting.

If not results are available, returns false.

◆ IsEmpty()

template<typename R , typename... Args>
bool vtkThreadedTaskQueue< R, Args >::IsEmpty ( ) const

Returns false if there's some result that may be popped right now or in the future.

◆ Flush()

template<typename R , typename... Args>
void vtkThreadedTaskQueue< R, Args >::Flush ( )

Blocks till the queue becomes empty.


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