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 (C) 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 (C) 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 (C) or Task Graph (C++).
Job Partner
Since API version 20, FFRT supports the Job_Partner feature. The job partner is often used for:
-
Multithreaded collaboration: In many real-world applications, some functionalities must run in a specific environment, while others can run in any environment. This is when multithreaded collaboration is needed: certain functionalities run in thread A, then switch back to thread B, and finally return to thread A.

-
Dynamic concurrent scheduling: In some scenarios, the number of concurrent tasks fluctuates dynamically. By adjusting the number of workers dynamically, you can maximize performance and reduce scheduling overhead.

The parameters in the figure are as follows:
job_num: number of submitted tasks.partner_num: number of workers.threshold: threshold for starting the worker.ratio: ratio of the number of tasks to the number of workers.max: maximum number of workers.
For details about the development example of the collaborative concurrency paradigm, see Job Partner (C++).