1
1
.. SPDX-FileCopyrightText: 2019-2021 Intel Corporation
2
+ .. SPDX-FileCopyrightText: 2025 UXL Foundation Contributors
2
3
..
3
4
.. SPDX-License-Identifier: CC-BY-4.0
4
5
@@ -62,9 +63,12 @@ A class that represents an explicit, user-managed task scheduler arena.
62
63
int max_concurrency() const;
63
64
64
65
template<typename F> auto execute(F&& f) -> decltype(f());
65
- template<typename F> void enqueue(F&& f);
66
66
67
+ template<typename F> void enqueue(F&& f);
68
+ template<typename F> void enqueue(F&& f, task_group& tg);
67
69
void enqueue(task_handle&& h);
70
+
71
+ task_group_status task_arena::wait_for(task_group& tg);
68
72
};
69
73
70
74
} // namespace tbb
@@ -263,7 +267,26 @@ Member functions
263
267
Returns the concurrency level of the ``task_arena ``.
264
268
Does not require the ``task_arena `` to be initialized and does not perform initialization.
265
269
266
- .. cpp :function :: template <F> void enqueue (F&& f)
270
+ .. cpp :function :: template <typename F> auto execute (F&& f) -> decltype(f())
271
+
272
+ Executes the specified functor in the ``task_arena `` and returns the value returned by the functor.
273
+ The ``F `` type must meet the `Function Objects ` requirements described in the [function.objects] section of the ISO C++ standard.
274
+
275
+ The calling thread joins the ``task_arena `` if possible, and executes the functor.
276
+ Upon return it restores the previous task scheduler state and floating-point settings.
277
+
278
+ If joining the ``task_arena `` is not possible, the call wraps the functor into a task,
279
+ enqueues it into the arena, waits using an OS kernel synchronization object
280
+ for another opportunity to join, and finishes after the task completion.
281
+
282
+ An exception thrown in the functor will be captured and re-thrown from ``execute ``.
283
+
284
+ .. note ::
285
+
286
+ Any number of threads outside of the arena can submit work to the arena and be blocked.
287
+ However, only the maximal number of threads specified for the arena can participate in executing the work.
288
+
289
+ .. cpp :function :: template <typename F> void enqueue (F&& f)
267
290
268
291
Enqueues a task into the ``task_arena `` to process the specified functor and immediately returns.
269
292
The ``F `` type must meet the `Function Objects ` requirements described in the [function.objects] section of the ISO C++ standard.
@@ -284,34 +307,28 @@ Member functions
284
307
285
308
An exception thrown and not caught in the functor results in undefined behavior.
286
309
287
- .. cpp :function :: template <F> auto execute (F&& f) -> decltype(f() )
310
+ .. cpp :function :: template <typename F> void enqueue (F&& f, task_group& tg )
288
311
289
- Executes the specified functor in the ``task_arena `` and returns the value returned by the functor.
290
- The ``F `` type must meet the `Function Objects ` requirements described in the [function.objects] section of the ISO C++ standard.
291
-
292
- The calling thread joins the ``task_arena `` if possible, and executes the functor.
293
- Upon return it restores the previous task scheduler state and floating-point settings.
312
+ Adds a task to process the specified functor into ``tg `` and enqueues it into the ``task_arena ``.
294
313
295
- If joining the ``task_arena `` is not possible, the call wraps the functor into a task,
296
- enqueues it into the arena, waits using an OS kernel synchronization object
297
- for another opportunity to join, and finishes after the task completion.
298
-
299
- An exception thrown in the functor will be captured and re-thrown from ``execute ``.
300
-
301
- .. note ::
302
-
303
- Any number of threads outside of the arena can submit work to the arena and be blocked.
304
- However, only the maximal number of threads specified for the arena can participate in executing the work.
314
+ The behavior of this function is equivalent to ``this->enqueue( tg.defer(std::forward<F>(f)) ) ``.
305
315
306
316
.. cpp :function :: void enqueue (task_handle&& h)
307
317
308
318
Enqueues a task owned by ``h `` into the ``task_arena `` for processing.
309
319
310
- The behavior of this function is identical to the generic version (``template<typename F> void task_arena::enqueue(F&& f) ``), except parameter type.
320
+ The behavior of this function is equivalent to the generic version (``template<typename F> void task_arena::enqueue(F&& f) ``), except parameter type.
311
321
312
322
.. note ::
313
323
``h `` should not be empty to avoid an undefined behavior.
314
324
325
+ .. cpp :function :: task_group_status task_arena::wait_for (task_group& tg)
326
+
327
+ Waits for all tasks in ``tg `` to complete or be cancelled, while possibly executing tasks in the ``task_arena ``.
328
+ Returns the status of ``tg `` once waiting is complete.
329
+
330
+ The behavior of this function is equivalent to ``this->execute([&tg]{ return tg.wait(); }) ``.
331
+
315
332
Example
316
333
-------
317
334
@@ -335,17 +352,13 @@ to the corresponding NUMA node.
335
352
}
336
353
337
354
for (int i = 0; i < numa_nodes.size(); i++) {
338
- arenas[i].execute([&task_groups, i] {
339
- task_groups[i].run([] {
340
- /* executed by the thread pinned to specified NUMA node */
341
- });
342
- });
355
+ arenas[i].enqueue([]{
356
+ /* executed by a thread pinned to the specified NUMA node */
357
+ }, task_groups[i]);
343
358
}
344
359
345
360
for (int i = 0; i < numa_nodes.size(); i++) {
346
- arenas[i].execute([&task_groups, i] {
347
- task_groups[i].wait();
348
- });
361
+ arenas[i].wait_for(task_groups[i]);
349
362
}
350
363
351
364
return 0;
0 commit comments