本页内容

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.