在本页

QtTaskTree::ParallelLimit Class

class QtTaskTree::ParallelLimit

具有自定义限制的并行执行模式。更多

头文件: #include <qtasktree.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
Qt 6.11
继承: QtTaskTree::ExecutionMode

注意:该类中的所有函数都是可重入的

公共函数

ParallelLimit(int limit)

详细说明

limit 定义了并行运行的直接子任务的最大数量:

  • limit 等于 0 时,没有限制,所有直接子任务都会一起启动,按照它们在组中出现的顺序。这意味着完全并行执行,可以使用parallel 元素代替。
  • limit 等于 1 时,表示同时只能运行一个子任务。这意味着顺序执行,可以使用sequential 元素代替。在这种情况下,子任务以链式运行,因此下一个子任务会在前一个子任务完成后开始。
  • 当传递其他正数作为limit 时,该组的子任务会并行运行,但同时运行的任务数量有限。限制定义了组中并行运行任务的最大数量。当组启动时,第一批任务开始运行(一批任务的数量最多等于所传递的limit ),其他任务则保持等待状态。当任何一个正在运行的任务结束时,组就会启动下一个剩余的任务,这样就不会超过组内同时运行任务的limit 。每个子任务结束时都会重复这一过程,直到所有子任务都启动为止。这样就可以限制同时运行任务的最大数量,例如,如果运行过多进程可能会长时间阻塞机器。

另请参阅 ExecutionMode

成员函数文档

ParallelLimit::ParallelLimit(int limit)

以给定的limit 构建并行执行模式。

另请参见 ExecutionMode

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.