HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WorkDispatcher Class Reference

#include <dispatcher.h>

Public Member Functions

WORK_API WorkDispatcher ()
 Construct a new dispatcher. More...
 
WORK_API ~WorkDispatcher ()
 Wait() for any pending tasks to complete, then destroy the dispatcher. More...
 
 WorkDispatcher (WorkDispatcher const &)=delete
 
WorkDispatcheroperator= (WorkDispatcher const &)=delete
 
template<class Callable >
void Run (Callable &&c)
 
template<class Callable , class A0 , class... Args>
void Run (Callable &&c, A0 &&a0, Args &&...args)
 
WORK_API void Wait ()
 Block until the work started by Run() completes. More...
 
WORK_API void Cancel ()
 

Detailed Description

A work dispatcher runs concurrent tasks. The dispatcher supports adding new tasks from within running tasks. This suits problems that exhibit hierarchical structured parallelism: tasks that discover additional tasks during their execution.

Typical use is to create a dispatcher and invoke Run() to begin doing work, then Wait() for the work to complete. Tasks may invoke Run() during their execution as they discover additional tasks to perform.

For example,

WorkDispatcher dispatcher;
for (i = 0; i != N; ++i) {
dispatcher.Run(DoSomeWork, workItem[i]);
}
dispatcher.Wait();

Calls to Run() and Cancel() may be made concurrently. Calls to Wait() may also be made concurrently. However, once any calls to Wait() are in-flight, calls to Run() and Cancel() must only be made by tasks already added by Run(). This means that users of this class are responsible to synchronize concurrent calls to Wait() to ensure this requirement is met.

Additionally, Wait() must never be called by a task added by Run(), since that task could never complete.

Definition at line 75 of file dispatcher.h.

Constructor & Destructor Documentation

WORK_API WorkDispatcher::WorkDispatcher ( )

Construct a new dispatcher.

WORK_API WorkDispatcher::~WorkDispatcher ( )

Wait() for any pending tasks to complete, then destroy the dispatcher.

WorkDispatcher::WorkDispatcher ( WorkDispatcher const &  )
delete

Member Function Documentation

WORK_API void WorkDispatcher::Cancel ( )

Cancel remaining work and return immediately.

Calling this function affects task that are being run directly by this dispatcher. If any of these tasks are using their own dispatchers to run tasks, these dispatchers will not be affected and these tasks will run to completion, unless they are also explicitly cancelled.

This call does not block. Call Wait() after Cancel() to wait for pending tasks to complete.

WorkDispatcher& WorkDispatcher::operator= ( WorkDispatcher const &  )
delete
template<class Callable >
void WorkDispatcher::Run ( Callable &&  c)
inline

Definition at line 105 of file dispatcher.h.

template<class Callable , class A0 , class... Args>
void WorkDispatcher::Run ( Callable &&  c,
A0 &&  a0,
Args &&...  args 
)
inline

Definition at line 110 of file dispatcher.h.

WORK_API void WorkDispatcher::Wait ( )

Block until the work started by Run() completes.


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