STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Concurrency::task_handle< _Function > Class Template Reference

The task_handle class represents an individual parallel work item. It encapsulates the instructions and the data required to execute a piece of work. More...

#include <ppl.h>

Inheritance diagram for Concurrency::task_handle< _Function >:
Concurrency::details::_UnrealizedChore Concurrency::details::_Chore Concurrency::details::_AllocBase

Public Member Functions

 task_handle (const _Function &_Func)
 Constructs a new task_handle object. The work of the task is performed by invoking the function specified as a parameter to the constructor. More...
 
 ~task_handle ()
 Destroys the task_handle object. More...
 
void operator() () const
 The function call operator that the runtime invokes to perform the work of the task handle. More...
 
- Public Member Functions inherited from Concurrency::details::_UnrealizedChore
 _UnrealizedChore ()
 
virtual ~_UnrealizedChore ()
 
void _Invoke ()
 
void _SetDetached (bool _FDetached)
 
Concurrency::details::_TaskCollectionBase_OwningCollection () const
 
void _SetRuntimeOwnsLifetime (bool fValue)
 
bool _GetRuntimeOwnsLifetime () const
 
void _PrepareSteal (ContextBase *_PContext)
 
- Public Member Functions inherited from Concurrency::details::_AllocBase
voidoperator new (size_t _Size)
 
void operator delete (void *_Ptr) throw ()
 
voidoperator new (size_t _Size, const std::nothrow_t &) throw ()
 
void operator delete (void *_Ptr, const std::nothrow_t &) throw ()
 
voidoperator new[] (size_t _Size)
 
void operator delete[] (void *_Ptr) throw ()
 
voidoperator new[] (size_t _Size, const std::nothrow_t &_No_throw) throw ()
 
void operator delete[] (void *_Ptr, const std::nothrow_t &_No_throw) throw ()
 
voidoperator new (size_t, void *_Location) throw ()
 
void operator delete (void *, void *) throw ()
 
void *__cdecl operator new[] (size_t, void *_Location) throw ()
 
void __cdecl operator delete[] (void *, void *) throw ()
 

Private Member Functions

task_handle const & operator= (task_handle const &)
 

Private Attributes

_Function _M_function
 

Friends

class task_group
 
class structured_task_group
 

Additional Inherited Members

- Static Public Member Functions inherited from Concurrency::details::_UnrealizedChore
template<typename _ChoreType , typename _Function >
static _ChoreType * _InternalAlloc (const _Function &_Func)
 
- Public Attributes inherited from Concurrency::details::_Chore
TaskProc m_pFunction
 
- Protected Member Functions inherited from Concurrency::details::_UnrealizedChore
_CRTIMP void _CheckTaskCollection ()
 
- Protected Member Functions inherited from Concurrency::details::_Chore
 _Chore (TaskProc _PFunction)
 
 _Chore ()
 
virtual ~_Chore ()
 
- Static Protected Member Functions inherited from Concurrency::details::_UnrealizedChore
template<typename _ChoreType >
static void __cdecl _InvokeBridge (void *_PContext)
 

Detailed Description

template<typename _Function>
class Concurrency::task_handle< _Function >

The task_handle class represents an individual parallel work item. It encapsulates the instructions and the data required to execute a piece of work.

Template Parameters
_FunctionThe type of the function object that will be invoked to execute the work represented by the task_handle object.

task_handle objects can be used in conjunction with a structured_task_group or a more general task_group object, to decompose work into parallel tasks. For more information, see Task Parallelism.

Note that the creator of a task_handle object is responsible for maintaining the lifetime of the created task_handle object until it is no longer required by the Concurrency Runtime. Typically, this means that the task_handle object must not destruct until either the wait or run_and_wait method of the task_group or structured_task_group to which it is queued has been called.

task_handle objects are typically used in conjunction with C++ lambdas. Because you do not know the true type of the lambda, the make_task function is typically used to create a task_handle object.

The runtime creates a copy of the work function that you pass to a task_handle object. Therefore, any state changes that occur in a function object that you pass to a task_handle object will not appear in your copy of that function object.

See also
task_group Class, structured_task_group Class, make_task Function, task_group::run Method, task_group::wait Method, task_group::run_and_wait Method, structured_task_group::run Method, structured_task_group::wait Method, structured_task_group::run_and_wait Method

Constructor & Destructor Documentation

template<typename _Function>
Concurrency::task_handle< _Function >::task_handle ( const _Function &  _Func)
inline

Constructs a new task_handle object. The work of the task is performed by invoking the function specified as a parameter to the constructor.

Parameters
_FuncThe function that will be invoked to execute the work represented by the task_handle object. This may be a lambda functor, a pointer to a function, or any object that supports a version of the function call operator with the signature void operator()().

The runtime creates a copy of the work function that you pass to the constructor. Therefore, any state changes that occur in a function object that you pass to a task_handle object will not appear in your copy of that function object.

100  : _M_function(_Func)
101  {
102  m_pFunction = reinterpret_cast <TaskProc> (&::Concurrency::details::_UnrealizedChore::_InvokeBridge<task_handle>);
103  }
TaskProc m_pFunction
Definition: concrt.h:4313
void(__cdecl * TaskProc)(void *)
Concurrency::details contains definitions of support routines in the public namespaces and one or mor...
Definition: concrt.h:265
_Function _M_function
Definition: ppl.h:136
template<typename _Function>
Concurrency::task_handle< _Function >::~task_handle ( )
inline

Destroys the task_handle object.

110  {
111  //
112  // We only need to perform a liveness check if the client owns the lifetime of the handle. Doing this for runtime owned handles
113  // is not only unnecessary -- it is also dangerous.
114  //
116  {
118  }
119  }
Concurrency::details::_TaskCollectionBase * _OwningCollection() const
Definition: concrt.h:4340
#define NULL
Definition: crtdbg.h:30
bool _GetRuntimeOwnsLifetime() const
Definition: concrt.h:4354

Member Function Documentation

template<typename _Function>
void Concurrency::task_handle< _Function >::operator() ( ) const
inline

The function call operator that the runtime invokes to perform the work of the task handle.

126  {
127  _M_function();
128  }
_Function _M_function
Definition: ppl.h:136
template<typename _Function>
task_handle const& Concurrency::task_handle< _Function >::operator= ( task_handle< _Function > const &  )
private

Friends And Related Function Documentation

template<typename _Function>
friend class structured_task_group
friend
template<typename _Function>
friend class task_group
friend

Member Data Documentation

template<typename _Function>
_Function Concurrency::task_handle< _Function >::_M_function
private

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