📄 ppl.h
字号:
/// </param>
/// <remarks>
/// If the <c>structured_task_group</c> destructs as the result of stack unwinding from an exception, you do not need to guarantee
/// that a call has been made to either the <c>wait</c> or <c>run_and_wait</c> method. In this case, the destructor will appropriately
/// cancel and wait for the task represented by the <paramref name="_Task_handle"/> parameter to complete.
/// <para>Throws an <see cref="invalid_multiple_scheduling Class">invalid_multiple_scheduling</see> exception if the task handle given by
/// the <paramref name="_Task_handle"/> parameter has already been scheduled onto a task group object via the <c>run</c> method and there has been
/// no intervening call to either the <c>wait</c> or <c>run_and_wait</c> method on that task group.</para>
/// </remarks>
/// <seealso cref="structured_task_group::wait Method"/>
/// <seealso cref="structured_task_group::run_and_wait Method"/>
/// <seealso cref="Task Parallelism"/>
/**/
template<class _Function>
void run(task_handle<_Function>& _Task_handle)
{
_Task_handle._SetRuntimeOwnsLifetime(false);
_M_task_collection._Schedule(&_Task_handle);
}
/// <summary>
/// Waits until all work on the <c>structured_task_group</c> has completed or is canceled.
/// </summary>
/// <returns>
/// An indication of whether the wait was satisfied or the task group was canceled, due to either an explicit cancel operation or an exception
/// being thrown from one of its tasks. For more information, see <see cref="task_group_status Enumeration">task_group_status</see>
/// </returns>
/// <remarks>
/// Note that one or more of the tasks scheduled to this <c>structured_task_group</c> object may execute inline on the calling context.
/// <para>If one or more of the tasks scheduled to this <c>structured_task_group</c> object throws an exception, the
/// runtime will select one such exception of its choosing and propagate it out of the call to the <c>wait</c> method.</para>
/// <para>Once this function returns, the <c>structured_task_group</c> object is considered in a final state and should not be used. Note that
/// utilization after the <c>wait</c> method returns will result in undefined behavior.</para>
/// <para>In the non-exceptional path of execution, you have a mandate to call either this method or the <c>run_and_wait</c> method before
/// the destructor of the <c>structured_task_group</c> executes.</para>
/// </remarks>
/// <seealso cref="structured_task_group::wait Method"/>
/// <seealso cref="structured_task_group::run_and_wait Method"/>
/// <seealso cref="Task Parallelism"/>
/**/
task_group_status wait()
{
//
// The underlying scheduler's definitions map exactly to the PPL's. No translation beyond the cast is necessary.
//
return (task_group_status)_M_task_collection._Wait();
}
/// <summary>
/// Schedules a task to be run inline on the calling context with the assistance of the <c>structured_task_group</c> object for full
/// cancellation support. If a <c>task_handle</c> object is passed as a parameter to <c>run_and_wait</c>, the caller is
/// responsible for managing the lifetime of the <c>task_handle</c> object. The function then waits until all work on the
/// <c>structured_task_group</c> object has either completed or been canceled.
/// </summary>
/// <typeparam name="_Function">
/// The type of the function object that will be invoked to execute the body of the task handle.
/// </typeparam>
/// <param name="_Task_handle">
/// A handle to the task which will be run inline on the calling context. Note that the caller has responsibility for the lifetime of this object.
/// The runtime will continue to expect it to live until the <c>run_and_wait</c> method finishes execution.
/// </param>
/// <returns>
/// An indication of whether the wait was satisfied or the task group was canceled, due to either an explicit cancel operation or an exception
/// being thrown from one of its tasks. For more information, see <see cref="task_group_status Enumeration">task_group_status</see>
/// </returns>
/// <remarks>
/// Note that one or more of the tasks scheduled to this <c>structured_task_group</c> object may execute inline on the calling context.
/// <para>If one or more of the tasks scheduled to this <c>structured_task_group</c> object throws an exception, the
/// runtime will select one such exception of its choosing and propagate it out of the call to the <c>run_and_wait</c> method.</para>
/// <para>Once this function returns, the <c>structured_task_group</c> object is considered in a final state and should not be used.
/// Note that utilization after the <c>run_and_wait</c> method returns will result in undefined behavior.</para>
/// <para>In the non-exceptional path of execution, you have a mandate to call either this method or the <c>wait</c> method before
/// the destructor of the <c>structured_task_group</c> executes.</para>
/// </remarks>
/// <seealso cref="structured_task_group::run Method"/>
/// <seealso cref="structured_task_group::wait Method"/>
/// <seealso cref="Task Parallelism"/>
/**/
template<class _Function>
task_group_status run_and_wait(task_handle<_Function>& _Task_handle)
{
//
// The underlying scheduler's definitions map exactly to the PPL's. No translation beyond the cast is necessary.
//
return (task_group_status)_M_task_collection._RunAndWait(&_Task_handle);
}
/// <summary>
/// Schedules a task to be run inline on the calling context with the assistance of the <c>structured_task_group</c> object for full
/// cancellation support. If a <c>task_handle</c> object is passed as a parameter to <c>run_and_wait</c>, the caller is
/// responsible for managing the lifetime of the <c>task_handle</c> object. The function then waits until all work on the
/// <c>structured_task_group</c> object has either completed or been canceled.
/// </summary>
/// <typeparam name="_Function">
/// The type of the function object that will be invoked to execute the task.
/// </typeparam>
/// <param name="_Func">
/// A function which will be called to invoke the body of the work. This may be a lambda or other object which supports
/// a version of the function call operator with the signature <c>void operator()()</c>.
/// </param>
/// <returns>
/// An indication of whether the wait was satisfied or the task group was canceled, due to either an explicit cancel operation or an exception
/// being thrown from one of its tasks. For more information, see <see cref="task_group_status Enumeration">task_group_status</see>
/// </returns>
/// <remarks>
/// Note that one or more of the tasks scheduled to this <c>structured_task_group</c> object may execute inline on the calling context.
/// <para>If one or more of the tasks scheduled to this <c>structured_task_group</c> object throws an exception, the
/// runtime will select one such exception of its choosing and propagate it out of the call to the <c>run_and_wait</c> method.</para>
/// <para>Once this function returns, the <c>structured_task_group</c> object is considered in a final state and should not be used.
/// Note that utilization after the <c>run_and_wait</c> method returns will result in undefined behavior.</para>
/// <para>In the non-exceptional path of execution, you have a mandate to call either this method or the <c>wait</c> method before
/// the destructor of the <c>structured_task_group</c> executes.</para>
/// </remarks>
/// <seealso cref="structured_task_group::run Method"/>
/// <seealso cref="structured_task_group::wait Method"/>
/// <seealso cref="Task Parallelism"/>
/**/
template<class _Function>
task_group_status run_and_wait(const _Function& _Func)
{
//
// The underlying scheduler's definitions map exactly to the PPL's. No translation beyond the cast is necessary.
//
task_handle<_Function> _Task(_Func);
return (task_group_status)_M_task_collection._RunAndWait(&_Task);
}
/// <summary>
/// Makes a best effort attempt to cancel the sub-tree of work rooted at this task group. Every task scheduled on the task group
/// will get canceled transitively if possible.
/// </summary>
/// <remarks>
/// For more information, see <see cref="Cancellation in the PPL"/>.
/// </remarks>
/**/
void cancel()
{
_M_task_collection._Cancel();
}
/// <summary>
/// Informs the caller whether or not the task group is currently in the midst of a cancellation. This
/// does not necessarily indicate that the <c>cancel</c> method was called on the <c>structured_task_group</c> object
/// (although such certainly qualifies this method to return <c>true</c>). It may be the case that the <c>structured_task_group</c> object
/// is executing inline and a task group further up in the work tree was canceled. In cases such as these where the runtime can determine ahead
/// of time that cancellation will flow through this <c>structured_task_group</c> object, <c>true</c> will be returned as well.
/// </summary>
/// <returns>
/// An indication of whether the <c>structured_task_group</c> object is in the midst of a cancellation (or is guaranteed to be shortly).
/// </returns>
/// <remarks>
/// For more information, see <see cref="Cancellation in the PPL"/>.
/// </remarks>
/**/
bool is_canceling()
{
return _M_task_collection._IsCanceling();
}
private:
// Disallow passing in an r-value for a task handle argument
template<class _Function> void run(task_handle<_Function>&& _Task_handle);
// The underlying group of tasks as known to the runtime.
::Concurrency::details::_StructuredTaskCollection _M_task_collection;
};
/// <summary>
/// The <c>task_group</c> class represents a collection of parallel work which can be waited on or canceled.
/// </summary>
/// <remarks>
/// Unlike the heavily restricted <c>structured_task_group</c> class, the <c>task_group</c> class is much more general construct.
/// It does not have any of the restrictions described by <see cref="structured_task_group Class">structured_task_group</see>. <c>task_group</c>
/// objects may safely be used across threads and utilized in free-form ways. The disadvantage of the <c>task_group</c> construct is that
/// it may not perform as well as the <c>structured_task_group</c> construct for tasks which perform small amounts of work.
/// <para>For more information, see <see cref="Task Parallelism"/>.</para>
/// </remarks>
/// <seealso cref="structured_task_group Class"/>
/// <seealso cref="task_handle Class"/>
/**/
class task_group
{
public:
/// <summary>
/// Constructs a new <c>task_group</c> object.
/// </summary>
/// <seealso cref="Task Parallelism"/>
/**/
task_group()
{
}
/// <summary>
/// Destroys a <c>task_group</c> object. You are expected to call the either the <c>wait</c> or <c>run_and_wait</c> method on the object
/// prior to the destructor executing, unless the destructor is executing as the result of stack unwinding due to an exception.
/// </summary>
/// <remarks>
/// If the destructor runs as the result of normal execution (e.g.: not stack unwinding due to an exception) and neither the <c>wait</c> nor
/// <c>run_and_wait</c> methods have been called, the destructor may throw a <see cref="missing_wait Class">missing_wait</see> exception.
/// </remarks>
/// <seealso cref="task_group::wait Method"/>
/// <seealso cref="task_group::run_and_wait Method"/>
/**/
~task_group()
{
}
/// <summary>
/// Schedules a task on the <c>task_group</c> object. If a <c>task_handle</c> object is passed as a parameter to <c>run</c>, the caller is
/// responsible for managing the lifetime of the <c>task_handle</c> object. The version of the method that takes a reference to a function
/// object as a parameter involves heap allocation inside the runtime which may be perform less well than using the version that takes a
/// reference to a <c>task_handle</c> object.
/// </summary>
/// <typeparam name="_Function">
/// The type of the function object that will be invoked to execute the body of the task handle.
/// </typeparam>
/// <param name="_Func">
/// A function which will be called to invoke the body of the task. This may be a lambda expression or other object which supports
/// a version of the function call operator with the signature <c>void operator()()</c>.
/// </param>
/// <remarks>
/// If the <c>task_group</c> destructs as the result of stack unwinding from an exception, you do not need to guarantee
/// that a call has been made to either the <c>wait</c> or <c>run_and_wait</c> method. In this case, the destructor will appropriately
/// cancel and wait for the task represented by the <paramref name="_Task_handle"/> parameter to complete.
/// <para>The method throws an <see cref="invalid_multiple_scheduling Class">invalid_multiple_scheduling</see> exception if the task
/// handle given by the <paramref name="_Task_handle"/> parameter has already been scheduled onto a task group object via the <c>run</c>
/// method and there has been no intervening call to either the <c>wait</c> or <c>run_and_wait</c> method on that task group.</para>
/// </remarks>
/// <seealso cref="task_group::wait Method"/>
/// <seealso cref="task_group::run_and_wait Method"/>
/// <seealso cref="Task Parallelism"/>
/**/
template<typename _Function>
void run(const _Function& _Func)
{
_M_task_collection._Schedule(::Concurrency::details::_UnrealizedChore::_InternalAlloc<task_handle<_Function>, _Function>(_Func));
}
/// <summary>
/// Schedules a task on the <c>task_group</c> object. If a <c>task_handle</c> object is passed as a parameter to <c>run</c>, the caller is
/// responsible for managing the lifetime of the <c>task_handle</c> object. The version of the method that takes a reference to a function
/// object as a parameter involves heap allocation inside the runtime which may be perform less well than using the version that takes a
/// reference to a <c>task_handle</c> object.
/// </summary>
/// <typeparam name="_Function">
/// The type of the function object that will be invoked to execute the body of the task handle.
/// </typeparam>
/// <param name="_Task_handle">
/// A handle to the work being scheduled. Note that the caller has responsibility for the lifetime of this object. The runtime will
/// continue to expect it to live until either the <c>wait</c> or <c>run_and_wait</c> method has been called on this
/// <c>task_group</c> object.
/// </param>
/// <remarks>
/// If the <c>task_group</c> destructs as the result of stack unwinding from an exception, you do not need to guarantee
/// that a call has been made to either the <c>wait</c> or <c>run_and_wait</c> method. In this case, the destructor will appropriately
/// cancel and wait for the task represented by the <paramref name="_Task_handle"/> parameter to complete.
/// <para>The method throws an <see cref="invalid_multiple_scheduling Class">invalid_multiple_scheduling</see> exception if the task
/// handle given by the <paramref name="_Task_handle"/> parameter has already been scheduled onto a task group object via the <c>run</c>
/// method and there has been no intervening call to either the <c>wait</c> or <c>run_and_wait</c> method on that task group.</para>
/// </remarks>
/// <seealso cref="task_group::wait Method"/>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -