concurrency 命名空間函式

Alloc

會透過並行執行階段的快取子配置器指定的大小,來配置記憶體區塊。

void* __cdecl Alloc(size_t _NumBytes);

參數

_NumBytes
要配置的記憶體位元組數目。

傳回值

新配置記憶體的指標。

備註

如需應用程式中哪些案例可能受益于使用快取子定位器的詳細資訊,請參閱 工作排程器

asend

非同步傳送作業,會排程工作將資料傳播到目標區塊。

template <class T>
bool asend(
    _Inout_ ITarget<T>* _Trg,
    const T& _Data);

template <class T>
bool asend(
    ITarget<T>& _Trg,
    const T& _Data);

參數

T
要傳送之資料的型別。

_Trg
傳送資料的目標指標或參考。

_資料
要傳送之資料的參考。

傳回值

true 如果在方法傳回之前接受訊息,則為 , false 否則為 。

備註

如需詳細資訊,請參閱 訊息傳遞函式

cancel_current_task

取消目前執行的工作。 這個函式可以從工作主體內呼叫,以中止工作執行並導致它進入 canceled 狀態。

如果不是在 task 的主體中,這就不是支援呼叫這個函式的情況。 這麼做會導致應用程式發生當機或無回應等未定義的行為。

inline __declspec(noreturn) void __cdecl cancel_current_task();

clear

清除並行佇列,終結任何目前排入佇列的專案。 這個方法不是並行安全的方法。

template<typename T, class _Ax>
void concurrent_queue<T, _Ax>::clear();

參數

T

_斧頭

create_async

以使用者提供的 Lambda 或函式物件為基礎,建立 Windows 執行階段非同步建構。 根據傳遞至方法的 Lambda 簽章,create_async 的傳回型別是下列其中一個:IAsyncAction^IAsyncActionWithProgress<TProgress>^IAsyncOperation<TResult>^IAsyncOperationWithProgress<TResult, TProgress>^

template<typename _Function>
__declspec(noinline) auto create_async(const _Function& _Func)
    -> decltype(ref new details::_AsyncTaskGeneratorThunk<_Function>(_Func));

參數

_功能
類型。

_Func
從中建立 Windows 執行階段非同步建構的 Lambda 或函式物件。

傳回值

由 IAsyncAction^、IAsyncActionWithProgress < TProgress > ^、IAsyncOperation < TResult^或 IAsyncOperationWithProgress TResult > 、 TProgress <> ^表示的非同步建構。 傳回的介面依賴傳遞至函式的 Lambda 簽章。

備註

Lambda 的傳回類型決定建構是動作或作業。

傳回 void 的 Lambda 造成動作的建立。 傳回屬於 TResult 類型之結果的 Lambda 會造成 TResult 作業的建立。

Lambda 可能也會傳回 task<TResult>,將非同步工作封裝在本身內或是表示非同步工作的工作鏈結的接續作業。 在這種情況下,Lambda 本身是內嵌執行,因為工作是非同步執行的工作,而且 Lambda 的傳回類型會解除包裝以產生 create_async 所傳回的非同步建構。 這表示傳回工作 < void > 的 Lambda 會導致建立動作,而傳回 < 工作 TResult 的 Lambda 將會導致建立 TResult > 的作業。

Lambda 可以接受零個、一個或兩個引數。 有效的引數為 progress_reporter<TProgress>cancellation_token,兩者都使用時依此順序。 沒有引數的 Lambda 會導致建立沒有進度報告功能的非同步建構。 採用progress_reporter < TProgress > 的 Lambda 會傳 create_async 回非同步建構,每次呼叫 progress_reporter 物件的 方法時 report ,都會報告 TProgress 類型的進度。 接受 cancellation_token 的 Lambda 可能使用該語彙基元來檢查取消的狀態,或是將語彙基元傳遞給所建立的工作,讓非同步建構的取消導致取消這些工作。

如果 Lambda 或函式物件的主體傳回結果(而非工作 < TResult > ),則 lamdba 會在執行時間隱含建立的工作內容中,以非同步方式在進程 MTA 內執行。 IAsyncInfo::Cancel 方法會導致取消隱含工作。

如果 Lambda 的主體傳回工作,則 Lambda 會內嵌執行,而且藉由宣告 Lambda 接受屬於類型 cancellation_token 的引數,您可以觸發任何工作的取消作業,這些工作是您建立工作時,透過傳入該語彙基元,在 Lambda 建立的。 您也可以在語彙基元使用 register_callback 方法,使執行階段在您在非同步作業或產生的動作呼叫 IAsyncInfo::Cancel 時叫用回呼。

此函式僅適用于Windows 執行階段應用程式。

CreateResourceManager

傳回代表並行執行階段資源管理員單一執行個體的介面。 資源管理員會負責將資源指派給想要與彼此相互合作的排程器。

IResourceManager* __cdecl CreateResourceManager();

傳回值

IResourceManager 介面。

備註

對此方法的多個後續呼叫會傳回相同的 Resource Manager 實例。 每次對 方法的呼叫都會遞增 Resource Manager 上的參考計數,而且必須在排程器與 Resource Manager 通訊完成時,與 IResourceManager::Release 方法的呼叫 進行比對。

如果並行執行時間不支援作業系統,則會擲回unsupported_os。

create_task

建立 PPL 工作 物件。 您可以在任何會使用工作建構函式的地方使用 create_task。 這主要是為了方便起見而提供,因為它允許在建立工作時使用 auto 關鍵字。

template<typename T>
__declspec(noinline) auto create_task(T _Param, const task_options& _TaskOptions = task_options())
    -> task<typename details::_TaskTypeFromParam<T>::T>;

template<typename _ReturnType>
__declspec( noinline) task<_ReturnType> create_task(const task<_ReturnType>& _Task);

參數

T
從中要建構工作的參數的類型。

_ReturnType
類型。

_參數
從中要建構工作的參數。 如果您使用 UWP 應用程式中的工作,這可能是 Lambda 或函式物件、 task_completion_event 物件、不同的 task 物件或 Windows::Foundation::IAsyncInfo 介面。

_TaskOptions
工作選項。

_任務
要建立的工作。

傳回值

T 別 的新工作,從 _Param 推斷。

備註

第一個多載的行為就像採用單一參數的工作建構函式一樣。

第二個多載會將所提供的取消權杖與新建立的工作產生關聯。 如果您使用這個多載,則不允許以第一個參數的形式傳入不同的 task 物件。

傳回工作的型別會從第一個參數推斷為 函式。 如果 _Param 是 、 task_completion_event<T>task<T> 或傳回 型 T 別或 task<T> 的函式,則所建立工作的型別為 task<T>

在 UWP 應用程式中,如果 _Param 類型為 Windows::Foundation::IAsyncOperation T > ^ 或 Windows::Foundation::IAsyncOperationWithProgress << T、P > ^或傳回其中一種類型的 functor,則所建立的工作會是 類型 task<T> 。 如果 _Param 類型為 Windows::Foundation::IAsyncAction^ 或 Windows::Foundation::IAsyncActionWithProgress < P > ^,或傳回其中一種類型的 functor,則建立的工作將會有類型 task<void>

DisableTracing

停用並行執行階段中的追蹤。 根據預設,這個函式因為 ETW 追蹤已移除註冊而被取代。

__declspec(deprecated("Concurrency::DisableTracing is a deprecated function.")) _CRTIMP HRESULT __cdecl DisableTracing();

傳回值

如果追蹤已正確停用, S_OK 則會傳回 。 如果先前未啟始追蹤,則會傳回 E_NOT_STARTED

EnableTracing

啟用並行執行階段中的追蹤。 根據預設,這個函式因為 ETW 追蹤已開啟而被取代。

__declspec(deprecated("Concurrency::EnableTracing is a deprecated function.")) _CRTIMP HRESULT __cdecl EnableTracing();

傳回值

如果已正確起始追蹤, S_OK 則會傳回 , E_NOT_STARTED 否則會傳回。

免費

釋放先前由 Alloc 方法配置的記憶體區塊至並行執行階段的快取子配置器。

void __cdecl Free(_Pre_maybenull_ _Post_invalid_ void* _PAllocation);

參數

_PAllocation
先前由要釋放之 方法所 Alloc 配置的記憶體指標。 如果 參數 _PAllocation 設定為 值 NULL ,這個方法將會忽略它並立即傳回。

備註

如需應用程式中哪些案例可能受益于使用快取子定位器的詳細資訊,請參閱 工作排程器

get_ambient_scheduler

inline std::shared_ptr<::Concurrency::scheduler_interface> get_ambient_scheduler();

傳回值

GetExecutionCoNtextId

傳回可指派給實作 IExecutionContext 介面之執行內容的唯一識別碼。

unsigned int __cdecl GetExecutionContextId();

傳回值

執行內容的唯一識別碼。

備註

使用這個方法,先取得執行內容的識別碼,再將介面當做參數傳遞 IExecutionContext 至 Resource Manager 提供的任何方法。

GetOSVersion

傳回作業系統版本。

IResourceManager::OSVersion __cdecl GetOSVersion();

傳回值

表示作業系統的列舉值。

備註

如果並行執行時間不支援作業系統,則會擲回unsupported_os。

GetProcessorCount

傳回基礎系統上的硬體執行緒數目。

unsigned int __cdecl GetProcessorCount();

傳回值

硬體執行緒數目。

備註

如果並行執行時間不支援作業系統,則會擲回unsupported_os。

GetProcessorNodeCount

傳回基礎系統上的 NUMA 節點或處理器套件數目。

unsigned int __cdecl GetProcessorNodeCount();

傳回值

NUMA 節點或處理器套件的數目。

備註

如果系統包含比處理器套件更多的 NUMA 節點,則會傳回 NUMA 節點數目,否則會傳回處理器套件數目。

如果並行執行時間不支援作業系統,則會擲回unsupported_os。

GetSchedulerId

傳回可指派給實作 IScheduler 介面之排程器的唯一識別碼。

unsigned int __cdecl GetSchedulerId();

傳回值

排程器的唯一識別碼。

備註

使用這個方法,先取得排程器的識別碼,再將介面當做參數傳遞 IScheduler 至 Resource Manager 提供的任何方法。

internal_assign_iterators

template<typename T, class _Ax>
template<class _I>
void concurrent_vector<T, _Ax>::internal_assign_iterators(
   _I first,
   _I last);

參數

T

_斧頭

_I

first

last

interruption_point

建立取消的中斷點。 如果這個函式呼叫的內容正在取消,則會擲出中止目前執行之平行工作執行的內部例外狀況。 如果取消不在進行中,函式不會執行任何動作。

inline void interruption_point();

備註

您不應該攔截 interruption_point() 函式擲回的內部取消例外狀況。 例外狀況會由執行階段攔截並處理,而攔截它可能會造成程式行為異常。

is_current_task_group_canceling

傳回指示,以說明目前正以內嵌方式在目前內容上執行的工作群組是否正在取消 (或即將取消)。 請注意,如果目前沒有任何工作群組以內嵌方式在目前的內容上執行,會傳回 false

bool __cdecl is_current_task_group_canceling();

傳回值

true 如果目前正在執行的工作群組正在取消,則為 , false 否則為 。

備註

如需詳細資訊,請參閱 取消

make_choice

從選擇性的 choiceScheduler 和兩個或多個輸入來源建立 ScheduleGroup 傳訊區塊。

template<typename T1, typename T2, typename... Ts>
choice<std::tuple<T1, T2, Ts...>> make_choice(
    Scheduler& _PScheduler,
    T1  _Item1,
    T2  _Item2,
    Ts... _Items);

template<typename T1, typename T2, typename... Ts>
choice<std::tuple<T1, T2, Ts...>> make_choice(
    ScheduleGroup& _PScheduleGroup,
    T1  _Item1,
    T2  _Item2,
    Ts... _Items);

template<typename T1, typename T2, typename... Ts>
choice<std::tuple<T1, T2, Ts...>> make_choice(
    T1  _Item1,
    T2  _Item2,
    Ts... _Items);

參數

T1
第一個來源的訊息區塊類型。

T2
第二個來源的訊息區塊類型。

_PScheduler
Scheduler 物件,在其內會排定 choice 傳訊區塊的傳播工作。

_Item1
第一個來源。

_Item2
第二個來源。

_專案
其他來源。

_PScheduleGroup
ScheduleGroup 物件,在其內會排定 choice 傳訊區塊的傳播工作。 所使用的 Scheduler 物件由排程群組所隱含。

傳回值

有兩個或多個輸入來源的 choice 訊息區塊。

make_greedy_join

從選擇性的 greedy multitype_joinScheduler 和兩個或多個輸入來源建立 ScheduleGroup 傳訊區塊。

template<typename T1, typename T2, typename... Ts>
multitype_join<std::tuple<T1, T2, Ts...>,greedy> make_greedy_join(
    Scheduler& _PScheduler,
    T1 _Item1,
    T2 _Item2,
    Ts... _Items);

template<typename T1, typename T2, typename... Ts>
multitype_join<std::tuple<T1, T2, Ts...>, greedy> make_greedy_join(
    ScheduleGroup& _PScheduleGroup,
    T1 _Item1,
    T2 _Item2,
    Ts... _Items);

template<typename T1, typename T2, typename... Ts>
multitype_join<std::tuple<T1, T2, Ts...>, greedy> make_greedy_join(
    T1 _Item1,
    T2 _Items,
    Ts... _Items);

參數

T1
第一個來源的訊息區塊類型。

T2
第二個來源的訊息區塊類型。

_PScheduler
Scheduler 物件,在其內會排定 multitype_join 傳訊區塊的傳播工作。

_Item1
第一個來源。

_Item2
第二個來源。

_專案
其他來源。

_PScheduleGroup
ScheduleGroup 物件,在其內會排定 multitype_join 傳訊區塊的傳播工作。 所使用的 Scheduler 物件由排程群組所隱含。

傳回值

有兩個或多個輸入來源的 greedy multitype_join 訊息區塊。

make_join

從選擇性的 non_greedy multitype_joinScheduler 和兩個或多個輸入來源建立 ScheduleGroup 傳訊區塊。

template<typename T1, typename T2, typename... Ts>
multitype_join<std::tuple<T1, T2, Ts...>>
    make_join(
Scheduler& _PScheduler,
    T1 _Item1,
    T2 _Item2,
    Ts... _Items);

template<typename T1, typename T2, typename... Ts>
multitype_join<std::tuple<T1, T2, Ts...>> make_join(
ScheduleGroup& _PScheduleGroup,
    T1 _Item1,
    T2 _Item2,
    Ts... _Items);

template<typename T1, typename T2, typename... Ts>
multitype_join<std::tuple<T1, T2, Ts...>> make_join(
    T1 _Item1,
    T2 _Item2,
    Ts... _Items);

參數

T1
第一個來源的訊息區塊類型。

T2
第二個來源的訊息區塊類型。

_PScheduler
Scheduler 物件,在其內會排定 multitype_join 傳訊區塊的傳播工作。

_Item1
第一個來源。

_Item2
第二個來源。

_專案
其他來源。

_PScheduleGroup
ScheduleGroup 物件,在其內會排定 multitype_join 傳訊區塊的傳播工作。 所使用的 Scheduler 物件由排程群組所隱含。

傳回值

有兩個或多個輸入來源的 non_greedy multitype_join 訊息區塊。

make_task

建立 task_handle 物件的 Factory 方法。

template <class _Function>
task_handle<_Function> make_task(const _Function& _Func);

參數

_功能
要叫用以執行 物件所 task_handle 表示之工作的函式物件型別。

_Func
將叫用以執行 物件所 task_handle 表示之工作的函式。 這可能是 Lambda 函式、函式的指標,或任何支援具有簽章 void operator()() 之函式呼叫運算子版本的物件。

傳回值

task_handle 物件。

備註

當您需要使用 Lambda 運算式建立 task_handle 物件時,此函式很有用,因為它可讓您建立物件,而不知道 Lambda 函式的真實類型。

parallel_buffered_sort

將指定範圍中的專案排列成非遞減順序,或根據二進位述詞所指定的排序準則平行排列。 這個函式語意與 std::sort 類似:皆是以比較為基礎、不穩定、就地排序的;差別為它需要 O(n) 額外的空間,且必須預設初始化需排序的項目。

template<typename _Random_iterator>
inline void parallel_buffered_sort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Allocator,
    typename _Random_iterator>
inline void parallel_buffered_sort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Allocator,
    typename _Random_iterator>
inline void parallel_buffered_sort(
    const _Allocator& _Alloc,
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Random_iterator,
    typename _Function>
inline void parallel_buffered_sort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Func,
    const size_t _Chunk_size = 2048);

template<typename _Allocator,
    typename _Random_iterator,
    typename _Function>
inline void parallel_buffered_sort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Func,
    const size_t _Chunk_size = 2048);

template<typename _Allocator,
    typename _Random_iterator,
    typename _Function>
inline void parallel_buffered_sort(
    const _Allocator& _Alloc,
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Func,
    const size_t _Chunk_size = 2048);

參數

_Random_iterator
輸入範圍的迭代器類型。

_分配器
C++ 標準程式庫相容記憶體配置器的型別。

_功能
二元比較子的類型。

_開始
隨機存取迭代器,用於定址要排序之範圍中第一個項目的位置。

_結束
隨機存取迭代器,用於定址要排序之範圍中越過最後一個項目的第一個位置。

_Alloc
C++ 標準程式庫相容記憶體配置器的實例。

_Func
使用者定義的述詞函式物件,用來定義順序中後續項目應符合的比較準則。 二元述詞會採用兩個引數,並且在符合時傳回 true,不符合時則傳回 false。 這個比較子函式必須對序列中項目的配對強制執行嚴格的弱式順序。

_Chunk_size
要分割成兩個進行並行執行的最小區塊大小。

備註

所有多載都需要 n * sizeof(T) 額外的空間,其中 n 是要排序的專案數目,而 T 是專案類型。 在大部分情況下,parallel_buffered_sort會顯示parallel_sort效能 的改善,而且如果您有可用的記憶體,您應該在parallel_sort使用它。

如果您未提供二進位比較子 std::less 做為預設值,則需要元素類型提供 運算子 operator<()

如果您未提供配置器類型或實例,則會使用 C++ 標準程式庫記憶體配置器 std::allocator<T> 來配置緩衝區。

演算法會將輸入範圍分成兩個區塊,接著在將每個區塊分成兩個子區塊以進行平行執行。 選擇性引數 _Chunk_size 可用來向演算法指出它應該以序列方式處理大小的 <_Chunk_size 區塊。

parallel_for

parallel_for 會逐一查看某個範圍的索引,並以平行方式在每個反覆項目上執行使用者提供的函式。

template <typename _Index_type, typename _Function, typename _Partitioner>
void parallel_for(
    _Index_type first,
    _Index_type last,
    _Index_type _Step,
    const _Function& _Func,
    _Partitioner&& _Part);

template <typename _Index_type, typename _Function>
void parallel_for(
    _Index_type first,
    _Index_type last,
    _Index_type _Step,
    const _Function& _Func);

template <typename _Index_type, typename _Function>
void parallel_for(
    _Index_type first,
    _Index_type last,
    const _Function& _Func,
    const auto_partitioner& _Part = auto_partitioner());

template <typename _Index_type, typename _Function>
void parallel_for(
    _Index_type first,
    _Index_type last,
    const _Function& _Func,
    const static_partitioner& _Part);

template <typename _Index_type, typename _Function>
void parallel_for(
    _Index_type first,
    _Index_type last,
    const _Function& _Func,
    const simple_partitioner& _Part);

template <typename _Index_type, typename _Function>
void parallel_for(
    _Index_type first,
    _Index_type last,
    const _Function& _Func,
    affinity_partitioner& _Part);

參數

_Index_type
用於反復專案的索引型別。

_功能
將在每次反覆運算執行之函式的類型。

_Partitioner
用來分割所提供範圍的分割器型別。

first
要包含在反復專案中的第一個索引。

last
在反覆運算中包含最後一個索引的索引前一個索引。

_步
逐一查看 至 lastfirst 要逐步執行的值。 步驟必須是正數。 如果步驟小於 1,則會擲回invalid_argument

_Func
要在每個反復專案上執行的函式。 這可能是 Lambda 運算式、函式指標,或任何支援具有簽章 void operator()(_Index_type) 之函式呼叫運算子版本的物件。

_部分
Partitioner 物件的參考。 引數可以是其中一個 const auto_partitioner &const static_partitioner &const simple_partitioner & affinity_partitioner & 如果使用 affinity_partitioner 物件,則參考必須是非 const l 值參考,讓演算法可以儲存狀態以供未來迴圈重複使用。

備註

如需詳細資訊,請參閱 平行演算法

parallel_for_each

parallel_for_each 會平行套用指定的函式到範圍內的每個項目。 在語意上,它相當於 std 命名空間中的 for_each 函式,但項目的反覆項目會平行執行,而且不會指定反覆項目的順序。 _Func 引數必須支援 operator()(T) 形式的函式呼叫運算子,其中 T 參數是要逐一查看之容器的項目類型。

template <typename _Iterator, typename _Function>
void parallel_for_each(
    _Iterator first,
    _Iterator last,
    const _Function& _Func);

template <typename _Iterator, typename _Function, typename _Partitioner>
void parallel_for_each(
    _Iterator first,
    _Iterator last,
    const _Function& _Func,
    _Partitioner&& _Part);

參數

_迭 代
用來逐一查看容器的反覆運算器類型。

_功能
將套用至範圍內每個元素的函式型別。

_Partitioner
first
反覆運算器,定址要包含在平行反覆運算中之第一個專案的位置。

last
反覆運算器,定址要包含在平行反復專案中最後一個專案後的位置。

_Func
套用至範圍中每個元素的使用者定義函式物件。

_部分
Partitioner 物件的參考。 引數可以是其中一個 const auto_partitioner &const static_partitioner &const simple_partitioner & affinity_partitioner & 如果使用 affinity_partitioner 物件,則參考必須是非 const l 值參考,讓演算法可以儲存狀態以供未來迴圈重複使用。

備註

auto_partitioner 將用於沒有明確資料分割器的多載。

對於不支援隨機存取的反覆運算器,僅 支援auto_partitioner

如需詳細資訊,請參閱 平行演算法

parallel_invoke

平行執行提供作為參數的函式物件,並加以封鎖直到完成執行為止。 函式物件可能是 Lambda 運算式、函式指標,或是支援函式呼叫運算子與簽章 void operator()() 版本的任何物件。

template <typename _Function1, typename _Function2>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2);

template <typename _Function1, typename _Function2, typename _Function3>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4,
    typename _Function5>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4,
    const _Function5& _Func5);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4,
    typename _Function5,
    typename _Function6>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4,
    const _Function5& _Func5,
    const _Function6& _Func6);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4,
    typename _Function5,
    typename _Function6,
    typename _Function7>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4,
    const _Function5& _Func5,
    const _Function6& _Func6,
    const _Function7& _Func7);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4,
    typename _Function5,
    typename _Function6,
    typename _Function7,
    typename _Function8>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4,
    const _Function5& _Func5,
    const _Function6& _Func6,
    const _Function7& _Func7,
    const _Function8& _Func8);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4,
    typename _Function5,
    typename _Function6,
    typename _Function7,
    typename _Function8,
    typename _Function9>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4,
    const _Function5& _Func5,
    const _Function6& _Func6,
    const _Function7& _Func7,
    const _Function8& _Func8,
    const _Function9& _Func9);

template <typename _Function1,
    typename _Function2,
    typename _Function3,
    typename _Function4,
    typename _Function5,
    typename _Function6,
    typename _Function7,
    typename _Function8,
    typename _Function9,
    typename _Function10>
void parallel_invoke(
    const _Function1& _Func1,
    const _Function2& _Func2,
    const _Function3& _Func3,
    const _Function4& _Func4,
    const _Function5& _Func5,
    const _Function6& _Func6,
    const _Function7& _Func7,
    const _Function8& _Func8,
    const _Function9& _Func9,
    const _Function10& _Func10);

參數

_Function1
要平行執行之第一個函式物件的型別。

_Function2
要平行執行的第二個函式物件的型別。

_Function3
要平行執行之第三個函式物件的型別。

_Function4
要平行執行的第四個函式物件的型別。

_Function5
要平行執行之第五個函式物件的型別。

_Function6
要平行執行的第六個函式物件的型別。

_Function7
要平行執行的第七個函式物件的型別。

_Function8
要平行執行之第八個函式物件的型別。

_Function9
要平行執行之第九個函式物件的型別。

_Function10
要平行執行之第十個函式物件的型別。

_Func1
要平行執行的第一個函式物件。

_Func2
要平行執行的第二個函式物件。

_Func3
要平行執行的第三個函式物件。

_Func4
要平行執行的第四個函式物件。

_Func5
要平行執行的第五個函式物件。

_Func6
要平行執行的第六個函式物件。

_Func7
要平行執行的第七個函式物件。

_Func8
要平行執行的第八個函式物件。

_Func9
要平行執行的第九個函式物件。

_Func10
要平行執行的第十個函式物件。

備註

請注意,提供做為參數的一或多個函式物件可能會在呼叫內容上內嵌執行。

如果作為參數傳遞至此函式的一或多個函式物件擲回例外狀況,執行時間會選取其選擇的其中一個例外狀況,並將其傳播出對 parallel_invoke 的呼叫。

如需詳細資訊,請參閱 平行演算法

parallel_radixsort

使用基數排序演算法,將指定範圍內的項目排列成非遞減順序。 這是一個穩定的排序函式,其需要可將項目排序成不帶正負號的整數機碼的投影函式。 要排序的項目都必須進行預設初始化。

template<typename _Random_iterator>
inline void parallel_radixsort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Allocator, typename _Random_iterator>
inline void parallel_radixsort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Allocator, typename _Random_iterator>
inline void parallel_radixsort(
    const _Allocator& _Alloc,
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Random_iterator, typename _Function>
inline void parallel_radixsort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Proj_func,
    const size_t _Chunk_size = 256* 256);

template<typename _Allocator, typename _Random_iterator,
    typename _Function>
inline void parallel_radixsort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Proj_func,
    const size_t _Chunk_size = 256* 256);

template<typename _Allocator,
    typename _Random_iterator,
    typename _Function>
inline void parallel_radixsort(
    const _Allocator& _Alloc,
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Proj_func,
    const size_t _Chunk_size = 256* 256);

參數

_Random_iterator
輸入範圍的迭代器類型。

_分配器
C++ 標準程式庫相容記憶體配置器的型別。

_功能
投影函式的類型。

_開始
隨機存取迭代器,用於定址要排序之範圍中第一個項目的位置。

_結束
隨機存取迭代器,用於定址要排序之範圍中越過最後一個項目的第一個位置。

_Alloc
C++ 標準程式庫相容記憶體配置器的實例。

_Proj_func
使用者定義的投影函式物件,可將專案轉換成整數值。

_Chunk_size
要分割成兩個進行並行執行的最小區塊大小。

備註

所有多載都需要 n * sizeof(T) 額外的空間,其中 n 是要排序的專案數目,而 T 是專案類型。 具有簽章 I _Proj_func(T) 的一元投影函式必須在指定專案時傳回索引鍵,其中 T 是專案類型,而且 I 是不帶正負號的整數類型。

如果您未提供投影函式,則只會傳回元素的預設投影函式會用於整數類型。 如果沒有投影函式,如果專案不是整數型別,函式將無法編譯。

如果您未提供配置器類型或實例,則會使用 C++ 標準程式庫記憶體配置器 std::allocator<T> 來配置緩衝區。

演算法會將輸入範圍分成兩個區塊,接著在將每個區塊分成兩個子區塊以進行平行執行。 選擇性引數 _Chunk_size 可用來向演算法指出它應該以序列方式處理大小的 <_Chunk_size 區塊。

parallel_reduce

以平行方式,透過計算後繼元素的部分總和來計算在一定範圍內所有項目的總和,或是計算部分後繼結果 (取得方式是使用指定的二進位運算而非總和運算得出) 的結果。 parallel_reduce 語意與 std::accumulate 類似;不同的是,它需要關聯的二進位運算,而且需要識別值而不是初始值。

template<typename _Forward_iterator>
inline typename std::iterator_traits<_Forward_iterator>::value_type parallel_reduce(
    _Forward_iterator _Begin,
    _Forward_iterator _End,
    const typename std::iterator_traits<_Forward_iterator>::value_type& _Identity);

template<typename _Forward_iterator, typename _Sym_reduce_fun>
inline typename std::iterator_traits<_Forward_iterator>::value_type parallel_reduce(
    _Forward_iterator _Begin,
    _Forward_iterator _End,
    const typename std::iterator_traits<_Forward_iterator>::value_type& _Identity,
    _Sym_reduce_fun _Sym_fun);

template<typename _Reduce_type,
    typename _Forward_iterator,
    typename _Range_reduce_fun,
    typename _Sym_reduce_fun>
inline _Reduce_type parallel_reduce(
    _Forward_iterator _Begin,
    _Forward_iterator _End,
    const _Reduce_type& _Identity,
    const _Range_reduce_fun& _Range_fun,
    const _Sym_reduce_fun& _Sym_fun);

參數

_Forward_iterator
輸入範圍的反覆運算器類型。

_Sym_reduce_fun
對稱縮減函式的類型。 這必須是具有簽章 _Reduce_type _Sym_fun(_Reduce_type, _Reduce_type) 的函式類型,其中_Reduce_type與身分識別類型和縮減的結果類型相同。 對於第三個多載,這應該與 的 _Range_reduce_fun 輸出類型一致。

_Reduce_type
輸入會減少的型別,這與輸入專案類型不同。 傳回值和識別值將具有此類型。

_Range_reduce_fun
範圍縮減函式的類型。 這必須是具有簽章 _Reduce_type _Range_fun(_Forward_iterator, _Forward_iterator, _Reduce_type) 的函式類型,_Reduce_type與身分識別類型和縮減的結果類型相同。

_開始
輸入反覆運算器,定址範圍中要減少的第一個專案。

_結束
輸入反覆運算器,定址物件是縮小範圍中最後一個專案以外的一個位置。

_身份
識別值 _Identity 的類型與縮減的結果類型相同,也是 value_type 第一個和第二個多載反覆運算器的 。 對於第三個多載,識別值的類型必須與縮減的結果類型相同,但與反覆運算器的不同 value_type 。 它必須有適當的值,讓範圍縮減運算子 _Range_fun 在套用至型別的單一元素範圍和識別值時,其行為就像從型 value_typevalue_type 別轉換成標識型別的數值型別一樣。

_Sym_fun
對稱函式,將用於縮減的第二個。 如需詳細資訊,請參閱。

_Range_fun
將在縮減的第一個階段中使用的函式。 如需詳細資訊,請參閱。

傳回值

縮減的結果。

備註

為了執行平行縮減,函式會根據基礎排程器可用的背景工作角色數目,將範圍分割成區塊。 縮減會以兩個階段進行,第一個階段會在每個區塊內執行縮減,而第二個階段則會在每個區塊的部分結果之間執行縮減。

第一個多載要求反覆運算器的 value_typeT 與識別數值型別以及縮減結果類型相同。 元素類型 T 必須提供 運算子 T T::operator + (T) ,以減少每個區塊中的元素。 第二個階段也會使用相同的運算子。

第二個多載也需要反覆運算器 value_type 與識別數值型別以及縮減結果類型相同。 提供的二進位運算子 _Sym_fun 會用於這兩個縮減階段,並將識別值當做第一個階段的初始值。

對於第三個多載,識別實數值型別必須與縮減結果類型相同,但反覆運算器的 value_type 可能與兩者不同。 範圍縮減函 _Range_fun 式會在第一個階段中使用識別值做為初始值,而二進位函 _Sym_reduce_fun 式會套用至第二個階段中的子結果。

parallel_sort

將指定範圍中的專案排列成非遞減順序,或根據二進位述詞所指定的排序準則平行排列。 這個函式語意與 std::sort 類似,皆是以比較為基礎、不穩定、就地排序的。

template<typename _Random_iterator>
inline void parallel_sort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End);

template<typename _Random_iterator,typename _Function>
inline void parallel_sort(
    const _Random_iterator& _Begin,
    const _Random_iterator& _End,
    const _Function& _Func,
    const size_t _Chunk_size = 2048);

參數

_Random_iterator
輸入範圍的迭代器類型。

_功能
二元比較子仿函數 (functor) 的類型。

_開始
隨機存取迭代器,用於定址要排序之範圍中第一個項目的位置。

_結束
隨機存取迭代器,用於定址要排序之範圍中越過最後一個項目的第一個位置。

_Func
使用者定義的述詞函式物件,用來定義順序中後續項目應符合的比較準則。 二元述詞會採用兩個引數,並且在符合時傳回 true,不符合時則傳回 false。 這個比較子函式必須對序列中項目的配對強制執行嚴格的弱式順序。

_Chunk_size
要分割成兩個區塊以進行平行執行的區塊大小下限。

備註

第一個多載使用二進位比較子 std::less

第二個多載會使用提供的二元比較子,該比較子應具有 bool _Func(T, T) 簽章,其中 T 是輸入範圍中項目的類型。

演算法會將輸入範圍分成兩個區塊,接著在將每個區塊分成兩個子區塊以進行平行執行。 選擇性引數 _Chunk_size 可用來向演算法指出它應該以序列方式處理大小的 <_Chunk_size 區塊。

parallel_transform

以平行方式,將指定的函式物件套用至來源範圍中的每個項目,或是一組來自兩個來源範圍的項目,並複製函式物件的傳回值到目的範圍。 此函式在語意上等於 std::transform

template <typename _Input_iterator1,
    typename _Output_iterator,
    typename _Unary_operator>
_Output_iterator parallel_transform(
    _Input_iterator1 first1,
    _Input_iterator1 last1,
    _Output_iterator _Result,
    const _Unary_operator& _Unary_op,
    const auto_partitioner& _Part = auto_partitioner());

template <typename _Input_iterator1,
    typename _Output_iterator,
    typename _Unary_operator>
_Output_iterator parallel_transform(
    _Input_iterator1 first1,
    _Input_iterator1 last1,
    _Output_iterator _Result,
    const _Unary_operator& _Unary_op,
    const static_partitioner& _Part);

template <typename _Input_iterator1,
    typename _Output_iterator,
    typename _Unary_operator>
_Output_iterator parallel_transform(
    _Input_iterator1 first1,
    _Input_iterator1 last1,
    _Output_iterator _Result,
    const _Unary_operator& _Unary_op,
    const simple_partitioner& _Part);

template <typename _Input_iterator1,
    typename _Output_iterator,
    typename _Unary_operator>
_Output_iterator parallel_transform(
    _Input_iterator1 first1,
    _Input_iterator1 last1,
    _Output_iterator _Result,
    const _Unary_operator& _Unary_op,
    affinity_partitioner& _Part);

template <typename _Input_iterator1,
    typename _Input_iterator2,
    typename _Output_iterator,
    typename _Binary_operator,
    typename _Partitioner>
_Output_iterator parallel_transform(
    _Input_iterator1 first1,
    _Input_iterator1 last1,
    _Input_iterator2
first2,
    _Output_iterator _Result,
    const _Binary_operator& _Binary_op,
    _Partitioner&& _Part);

template <typename _Input_iterator1,
    typename _Input_iterator2,
    typename _Output_iterator,
    typename _Binary_operator>
_Output_iterator parallel_transform(
    _Input_iterator1 first1,
    _Input_iterator1 last1,
    _Input_iterator2
first2,
    _Output_iterator _Result,
    const _Binary_operator& _Binary_op);

參數

_Input_iterator1
第一個或唯一一個輸入迭代器的類型。

_Output_iterator
輸出反覆運算器的型別。

_Unary_operator
在輸入範圍內的每個項目上執行的一元仿函數 (functor) 類型。

_Input_iterator2
第二個輸入迭代器的類型。

_Binary_operator
在兩個來源範圍的項目上成對執行的二元仿函數 (functor) 類型。

_Partitioner
first1
輸入迭代器,用於定址在第一個或唯一一個來源範圍上執行之第一個項目的位置。

last1
輸入迭代器,用於定址超過要在第一個或唯一一個來源範圍中執行之最後一個項目的第一個位置。

_結果
輸出迭代器,用於定址目的範圍中第一個項目的位置。

_Unary_op
套用至來源範圍中每個項目的使用者定義一元函式物件。

_部分
Partitioner 物件的參考。 引數可以是其中一個 const auto_partitioner &const static_partitioner &const simple_partitioner & affinity_partitioner & 如果使用 affinity_partitioner 物件,則參考必須是非 const l 值參考,讓演算法可以儲存狀態以供未來迴圈重複使用。

first2
輸入迭代器,用於定址第二個來源範圍中要執行之第一個項目的位置。

_Binary_op
使用者定義的二元函式物件,它會以正向順序成對套用至兩個來源範圍。

傳回值

輸出迭代器,用於定址超過接收函式物件所轉換之輸出項目的目的範圍中最後一個項目的第一個位置。

備註

auto_partitioner將用於沒有明確資料分割器引數的多載。

對於不支援隨機存取的反覆運算器,僅 支援auto_partitioner

採用 _Unary_op 引數的多載會透過將一元仿函數套用至輸出範圍中的每個項目,將輸入範圍轉換成輸出範圍。 _Unary_op 必須支援具有 operator()(T) 簽章的函式呼叫運算子,其中 T 是反覆查看之範圍的實值類型。

採用 _Binary_op 引數的多載會透過將二元仿函數套用至第一個輸入範圍的某一個項目和第二個輸入範圍的某一個項目,將兩個輸入範圍轉換成輸出範圍。 _Binary_op 必須支援具有 operator()(T, U) 簽章的函式呼叫運算子,其中 TU 為兩個輸入迭代器的實值類型。

如需詳細資訊,請參閱 平行演算法

接收

一般接收實作,可讓內容等候來自一個來源的資料,並且篩選所接受的值。

template <class T>
T receive(
    _Inout_ ISource<T>* _Src,
    unsigned int _Timeout = COOPERATIVE_TIMEOUT_INFINITE);

template <class T>
T receive(
    _Inout_ ISource<T>* _Src,
    typename ITarget<T>::filter_method const& _Filter_proc,
    unsigned int _Timeout = COOPERATIVE_TIMEOUT_INFINITE);

template <class T>
T receive(
    ISource<T>& _Src,
    unsigned int _Timeout = COOPERATIVE_TIMEOUT_INFINITE);

template <class T>
T receive(
    ISource<T>& _Src,
    typename ITarget<T>::filter_method const& _Filter_proc,
    unsigned int _Timeout = COOPERATIVE_TIMEOUT_INFINITE);

參數

T
承載類型。

_Src
預期資料的來源指標或參考。

_超時
方法應該針對資料的時間上限,以毫秒為單位。

_Filter_proc
篩選函式,決定是否應接受訊息。

傳回值

來自承載類型的來源值。

備註

如果 參數 _Timeout 的值不是常數 COOPERATIVE_TIMEOUT_INFINITE ,則如果指定的時間量在收到訊息之前到期,則會擲回例外 狀況operation_timed_out 。 如果您想要零長度逾時,則應該使用 try_receive 函式,而不是以逾時 (零) 的逾 0 時呼叫 receive ,因為它更有效率,而且不會在逾時時擲回例外狀況。

如需詳細資訊,請參閱 訊息傳遞函式

run_with_cancellation_token

在指定的取消語彙基元內容中立即和同步地執行函式物件。

template<typename _Function>
void run_with_cancellation_token(
    const _Function& _Func,
    cancellation_token _Ct);

參數

_功能
將要叫用的函式物件類型。

_Func
要執行的函式物件。 這個物件必須支援具有 void(void) 簽章的函式呼叫運算子。

_Ct
將控制函式物件之隱含取消作業的取消語彙基元。 如果您想要執行函式,而不會從要取消的父工作群組隱含取消,請使用 cancellation_token::none()

備註

函式物件中的所有中斷點都會在 cancellation_token 取消時觸發。 如果父項擁有不同的語彙基元或沒有語彙基元,則明確的語彙基元 _Ct 會將這個 _Func 與父取消隔離。

傳送

同步傳送作業,其會等候直到目標接受或拒絕訊息。

template <class T>
bool send(_Inout_ ITarget<T>* _Trg, const T& _Data);

template <class T>
bool send(ITarget<T>& _Trg, const T& _Data);

參數

T
承載類型。

_Trg
傳送資料的目標指標或參考。

_資料
要傳送之資料的參考。

傳回值

true 如果已接受訊息,則為 , false 否則為 。

備註

如需詳細資訊,請參閱 訊息傳遞函式

set_ambient_scheduler

inline void set_ambient_scheduler(std::shared_ptr<::Concurrency::scheduler_interface> _Scheduler);

參數

_調度
要設定的環境排程器。

set_task_execution_resources

依據指定的同質性集,限制並行執行階段之內部背景工作執行緒使用的執行資源。

只有在資源管理員建立之前,或在兩個資源管理員存留期之間,才能有效地呼叫這個方法。 只要資源管理員不在引動過程期間,即可多次叫用此函式。 在同質性限制設定之後,直到下次有效呼叫 set_task_execution_resources 方法之前,該限制會持續有效。

提供的同質性遮罩不需為處理序同質性遮罩的子集。 您可視需要更新處理序的同質性遮罩。

void __cdecl set_task_execution_resources(
    DWORD_PTR _ProcessAffinityMask);

void __cdecl set_task_execution_resources(
    unsigned short count,
    PGROUP_AFFINITY _PGroupAffinity);

參數

_ProcessAffinityMask
要做為並行執行階段背景工作執行緒之限制的同質性遮罩。 只有在您想要將並行執行階段限制於目前處理器群組的子集時,才在有超過 64 個硬體執行緒的系統上使用這個方法。 一般而言,您應該使用接受群組同質性陣列做為參數的方法版本,以便在擁有超過 64 個硬體執行緒的電腦上限制同質性。

計數
GROUP_AFFINITY 參數所指定之陣列中 _PGroupAffinity 元素的數目。

_PGroupAffinity
GROUP_AFFINITY 元素的陣列。

備註

如果叫用 Resource Manager 時存在,方法會擲回 invalid_operation 例外狀況,如果 指定的同質性會導致空的資源集,則會擲回invalid_argument 例外狀況。

採用群組同質性陣列做為參數的方法版本只可在執行 Windows 7 (含) 以上版本的作業系統上使用。 否則,會 擲回invalid_operation 例外狀況。

叫用此方法之後以程式設計方式修改進程親和性,不會讓 Resource Manager 重新評估其限制的親和性。 因此,對處理序同質性的所有變更都應該在呼叫這個方法之前進行。

swap

交換兩個 concurrent_vector 物件的項目。

template<typename T, class _Ax>
inline void swap(
    concurrent_vector<T, _Ax>& _A,
    concurrent_vector<T, _Ax>& _B);

參數

T
儲存在並行向量中的專案資料類型。

_斧頭
並行向量的配置器類型。

_A
並行向量,其專案要與並行向量 _B 交換。

_B
提供要交換之元素的並行向量,或要與並行向量交換其元素的向量 _A

備註

範本函式是容器類別 concurrent_vector 上特製化的演算法,可執行成員函式 _Aconcurrent_vector::swap _B )。 這是編譯器所執行函式樣板部分排序的執行個體。 若因樣板函式多載而導致樣板與函式呼叫的比對不是唯一,則編譯器就會選取特製化程度最高的樣板函式版本。 演算法類別中範本函 template <class T> void swap(T&, T&) 式的一般版本會依指派運作,而且是緩慢的作業。 每個容器中的特製化版本運作速度會更快,因為它可以與容器類別的內部表示法一起運作。

這個方法不是並行安全的方法。 當您呼叫此方法時,您必須確定沒有任何其他執行緒在任一併行向量上執行作業。

task_from_exception

template<typename _TaskType, typename _ExType>
task<_TaskType> task_from_exception(
    _ExType _Exception,
    const task_options& _TaskOptions = task_options());

參數

_TaskType

_ExType

_例外

_TaskOptions

傳回值

task_from_result

template<typename T>
task<T> task_from_result(
    T _Param,
    const task_options& _TaskOptions = task_options());

inline task<bool> task_from_result(ool _Param);

inline task<void> task_from_result(
    const task_options& _TaskOptions = task_options());

參數

T

_參數

_TaskOptions

傳回值

Trace_agents_register_name

將指定的名稱與 ETW 追蹤的訊息區塊或代理程式產生關聯。

template <class T>
void Trace_agents_register_name(
    _Inout_ T* _PObject,
    _In_z_ const wchar_t* _Name);

參數

T
物件的類型。 這通常是訊息區塊或代理程式。

_PObject
要在追蹤中命名的訊息區塊或代理程式的指標。

_名字
所指物件的名稱。

try_receive

一般嘗試-接收實作,可讓內容尋找來自特定一個來源的資料,並且篩選所接受的值。 如果資料尚未就緒,方法會傳回 false

template <class T>
bool try_receive(_Inout_ ISource<T>* _Src, T& _value);

template <class T>
bool try_receive(
    _Inout_ ISource<T>* _Src,
    T& _value,
    typename ITarget<T>::filter_method const& _Filter_proc);

template <class T>
bool try_receive(ISource<T>& _Src, T& _value);

template <class T>
bool try_receive(
    ISource<T>& _Src,
    T& _value,
    typename ITarget<T>::filter_method const& _Filter_proc);

參數

T
承載類型

_Src
預期資料的來源指標或參考。

_價值
將放置結果之位置的參考。

_Filter_proc
篩選函式,決定是否應接受訊息。

傳回值

bool值,指出承載是否放置於 中 _value

備註

如需詳細資訊,請參閱 訊息傳遞函式

wait

暫停目前的內容達指定的時間長度。

void __cdecl wait(unsigned int _Milliseconds);

參數

_毫秒
目前內容應該暫停的毫秒數。 如果 _Milliseconds 參數設定為數值 0,則目前內容應該會先執行其他可執行的內容,然後再繼續進行。

備註

如果在並行執行時間排程器內容上呼叫這個方法,排程器會尋找在基礎資源上執行的不同內容。 由於排程器是合作性質,因此在指定的毫秒數之後,這個內容不會確實繼續進行。 如果排程器忙於執行其他不能配合排程器的工作,則等候期間可能會是無限期。

when_all

建立工作,這個工作將會在當做引數提供的所有工作都已順利完成時成功完成。

template <typename _Iterator>
auto when_all(
    _Iterator _Begin,
    _Iterator _End,
    const task_options& _TaskOptions = task_options()) ->
    decltype (details::_WhenAllImpl<typename std::iterator_traits<_Iterator>::value_type::result_type,
    _Iterator>::_Perform(_TaskOptions, _Begin,  _End));

參數

_迭 代
輸入迭代器的類型。

_開始
合併至所產生工作之項目範圍內的第一個項目位置。

_結束
合併至所產生工作之項目範圍外的第一個項目位置。

_TaskOptions
task_options 物件。

傳回值

當所有輸入工作都成功完成時,成功完成的工作。 如果輸入工作屬於類型 T,此函式的輸出將會是 task<std::vector<T>>。 如果輸入工作屬於類型 void,則輸出工作也會是 task<void>

備註

when_all 是未封鎖的函式,會產生 task 做為其結果。 不同于 task::wait ,在 ASTA (Application STA) 執行緒上的 UWP 應用程式中呼叫此函式是安全的。

如果其中一個工作取消或擲回例外狀況,則傳回的工作會提早完成,處於已取消狀態,如果發生例外狀況,如果您呼叫 task::get task::wait 在該工作上擲回例外狀況。

如需詳細資訊,請參閱 工作平行處理原則

when_any

建立工作,這個工作會在當做引數提供的所有工作都順利完成時,順利完成。

template<typename _Iterator>
auto when_any(
    _Iterator _Begin,
    _Iterator _End,
    const task_options& _TaskOptions = task_options())
    -> decltype (
        details::_WhenAnyImpl<
            typename std::iterator_traits<_Iterator>::value_type::result_type,
            _Iterator>::_Perform(_TaskOptions, _Begin, _End));

template<typename _Iterator>
auto when_any(
    _Iterator _Begin,
    _Iterator _End,
    cancellation_token _CancellationToken)
       -> decltype (
           details::_WhenAnyImpl<
               typename std::iterator_traits<_Iterator>::value_type::result_type,
               _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End));

參數

_迭 代
輸入迭代器的類型。

_開始
合併至所產生工作之項目範圍內的第一個項目位置。

_結束
合併至所產生工作之項目範圍外的第一個項目位置。

_TaskOptions
_CancellationToken
取消語彙基元,控制傳回工作的取消作業。 如果未提供取消語彙基元,產生的工作將會收到導致其完成之工作的取消語彙基元。

傳回值

一項工作會在所有輸入工作都順利完成時,順利完成。 如果輸入工作的類型為 T,則這個函式的輸出會是 task<std::pair<T, size_t>>>,其中配對的第一個項目是完成工作的結果,而第二個項目是已完成工作的索引。 如果輸入工作的類型為 void,則輸出是 task<size_t>,其中結果是完成工作的索引。

備註

when_any 是未封鎖的函式,會產生 task 做為其結果。 不同于 task::wait ,在 ASTA (Application STA) 執行緒上的 UWP 應用程式中呼叫此函式是安全的。

如需詳細資訊,請參閱 工作平行處理原則

另請參閱

concurrency 命名空間