harmony 鸿蒙Function Flow Runtime Paradigms
Function Flow Runtime Paradigms
To cope with fixed task execution sequence, flexible priority-based scheduling, and complex task dependencies in actual services, Function Flow Runtime (FFRT) supports three paradigms: serial queue, concurrent queue, and task graph.
Serial Queue
The serial queue is often used for:
- Sequential execution: The serial queue ensures that tasks are executed one by one in sequence, avoiding data inconsistency and errors caused by out-of-order execution.
- Data security: The serial queue prevents multiple threads from competing for shared resources concurrently, ensuring data consistency and security.
- Task scheduling: The serial queue can schedule the execution sequence of complex tasks. For example, it ensures that a task begins after the previous one completes when tasks with multiple dependencies are performed.
- Simplified development: The serial queue is more simple and clear compared with manual mutex management and synchronization. You only need to add tasks to the queue for automatic system scheduling and execution, simplifying development and debugging.
- Resource management: The serial queue can limit the number of concurrent tasks and avoid resource competition and overload, optimizing system resource usage.
For details about the development sample, see Serial Queue © or Serial Queue (C++).
Concurrent Queue
The concurrent queue is often used for:
- Concurrency improvement: The concurrent queue allows concurrent execution of multiple tasks, fully utilizing the computing capability of the multi-core processor and significantly improving the concurrency and overall performance of the system.
- Efficient resource utilization: The concurrent queue can allocate tasks to available CPU cores to optimize resource usage and reduce task waiting time and resource competition.
- Flexible task scheduling: The concurrent queue can schedule tasks based on priorities and QoS to ensure that key tasks can be executed in a timely manner and improve the system response speed.
- Resource impact prevention: The concurrent queue can set the maximum concurrency to avoid system resource impact caused by excessive concurrent tasks, ensuring system stability and performance.
For details about the development sample, see Concurrent Queue © or Concurrent Queue (C++).
Task Graph
The task graph is often used for:
- Complex task dependency: In actual applications, tasks have complex dependencies among each other. The task graph represents task dependencies by using directed graphs to clearly manage and schedule tasks.
- Dynamic task scheduling: The task graph can dynamically adjust task scheduling and dependencies and execution sequence according to the running conditions.
- Concurrent task execution: The task graph allows multiple independent tasks to be executed concurrently, making full use of system computing resources and improving concurrency and execution efficiency.
- Structured concurrency: The clear task lifecycles and dependencies in the task graph ensure that the creation and completion of concurrent tasks are explicit in the code structure, reducing the complexity and errors of concurrent programming.
For details about the development sample, see Task Graph © or Task Graph (C++).
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Function Flow Runtime C APIs
harmony 鸿蒙Function Flow Runtime Concurrent Queue ©
harmony 鸿蒙Function Flow Runtime Concurrent Queue (C++)
harmony 鸿蒙Function Flow Runtime Task Graph ©
harmony 鸿蒙Function Flow Runtime Task Graph (C++)
harmony 鸿蒙Function Flow Runtime Serial Queue ©
harmony 鸿蒙Function Flow Runtime Serial Queue (C++)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦