Multi-thread task partition management method

Through the multi-threaded task partition management method, the dual search mechanism of thread label and task category is used to solve the problem of inefficiency in the case of too many threads in the traditional multi-threaded management method, and efficient thread resource allocation and system performance improvement are achieved.

CN119003123APending Publication Date: 2024-11-22GUILIN UNIV OF ELECTRONIC TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411106070.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

When there are too many threads in the thread pool, the traditional multithreading management method is inefficient and cannot effectively improve the search speed and processing performance of threads.

Method used

Adopt multi-threaded task partition management method, by assigning unique labels and task categories to each thread, priority processing of emergency tasks in the task queue, and quickly locate and allocate thread resources through the dual search mechanism, reducing traversal of the entire thread pool and improving resources Distribution efficiency.

Benefits of technology

It improves thread management efficiency, reduces task scheduling and search time, ensures system performance, realizes timely updates and load balancing of resources, and ensures efficient operation of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003123A_ABST
    Figure CN119003123A_ABST
Patent Text Reader

Abstract

The invention provides a multi-thread task partition management method. The method comprises the following steps: firstly, creating a thread pool containing a plurality of threads, distributing a unique label, an execution state and a task category for each thread, acquiring a to-be-processed task, distributing a task category and a priority, adding the task to a task queue, then judging whether an emergency task exists in the task queue, and if the emergency task exists, executing the task according to the emergency task. If yes, stopping a task with the lowest priority, releasing thread resources used by the task and reallocating the thread resources to the emergency tasks, if no emergency tasks exist, extracting the tasks from the task queue according to the priorities, recursively allocating the tasks for the threads, classifying the threads of the same task category into one thread group, and after the tasks are executed, executing the tasks again. And performing related task processing on the used thread, continuously using the thread by the related task, releasing the thread if no related task exists, and repeating the process until all tasks are completed. According to the method, task identifiers are added to all threads, a thread task regionalization management mode is adopted, and thread resources are quickly positioned and allocated through a dual search mechanism, so that the overall management efficiency is improved. When the task of each thread is executed, the related tasks are preferentially allocated, it is ensured that the tasks in the same group are preferentially processed, task allocation and resource management can be more efficiently adjusted in real time, and efficient utilization of resources and normal operation of a system are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of multi-thread management, and in particular to a multi-thread task partition management method. Background Art

[0002] With the development of computer hardware and software technology, multithreading has become one of the key technologies to improve computer performance. Multithreading technology is a technology widely used in modern computer systems to improve processor utilization and parallel processing capabilities of tasks.

[0003] When an urgent task is added and all threads in the thread pool are in use, the traditional multi-thread management method usually determines the task priority and terminates the thread with a high priority to preempt the thread with a low priority, and assigns it to the urgent task to process, thereby achieving dynamic task scheduling. However, this method requires traversing the entire thread pool, and is inefficient when there are too many threads in the thread pool.

[0004] Therefore, a more efficient, flexible and dynamically adjustable multi-thread management method is needed to improve the search speed and processing performance of threads, so as to solve the problem of low thread management efficiency in the prior art. Application Contents

[0005] The present application provides a multi-threaded task partition management method for solving the problem of low thread management efficiency in the prior art.

[0006] The present application provides a multi-threaded task partition management method, the multi-threaded task management method comprising:

[0007] Create a thread pool containing multiple threads and assign each thread a unique thread label V, execution state S and task category T t ;

[0008] Get pending tasks and assign them task category T m and priority P (P>0);

[0009] Add the task to the task queue;

[0010] Determine whether there are urgent tasks in the task queue;

[0011] If there is an urgent task, stop the task with the lowest priority, release the thread resources it uses and reallocate them to the urgent task;

[0012] If there is no urgent task, take the task from the task queue according to P, recursively assign the task to the thread, update S to the running state and T t =T m ,Threads of the same task category are assigned to a thread group;

[0013] When a task is completed, update the S of the thread to the waiting state;

[0014] Process the related tasks for the thread. The related tasks continue to use the thread. If there are no related tasks, release the thread, update S to idle and clear T t ;

[0015] Repeat the above process until all tasks are completed.

[0016] Compared with the traditional multi-thread management method, this application has the following advantages.

[0017] Thread partition management: Assign tasks to different areas, each area is handled by a group of threads. Compared with global management, partition management reduces the search range of threads, reduces the time for scheduling and searching each task, and improves system performance.

[0018] Double search mechanism: Through the double search mechanism of task category and thread label, thread resources can be efficiently located and allocated, avoiding traversal of the entire thread pool and improving resource allocation efficiency.

[0019] Timely status update: Assigning execution status to threads can respond to task availability and real-time changes in thread load more promptly, better load balance and reduce idle time, quickly adjust task allocation, and ensure efficient operation of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 This is a flowchart corresponding to a multi-threaded task partition management method of the present application.

[0021] Figure 2 This is a flowchart of emergency task processing when there is no idle thread in the implementation mode of this application. DETAILED DESCRIPTION

[0022] The implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0023] In order to solve the problems of the prior art, an embodiment of the present application provides a multi-threaded task partition management method, which is specifically used to solve the problem of low thread management efficiency when there are too many threads in a thread pool.

[0024] like Figure 1 The figure is a flowchart corresponding to a multi-threaded task partition management method provided in the embodiment of the present application. Specifically, it includes the following steps:

[0025] Step 1: Create a thread pool containing multiple threads and assign each thread a unique thread number V, execution state S and task category T. t ;

[0026] Step 2: Get pending tasks and assign them task category T m and priority P (P>0);

[0027] Step 3, add the task to the task queue;

[0028] Step 4, determine whether there is an urgent task in the task queue, if there is an urgent task, execute step 5, if there is no urgent task, execute step 6;

[0029] Step 5: Stop a task with the lowest priority, release the thread resources it uses and reallocate them to the urgent task;

[0030] Step 6: Take tasks from the task queue according to priority, recursively assign tasks to threads, and update S to the running state and T t =T m ,Threads of the same task category are assigned to a thread group;

[0031] Step 7: When a task is completed, update the S of the thread to the waiting state;

[0032] Step 8: Process related tasks for the thread. If there are no related tasks, release the thread, update S to idle and clear T. t ;

[0033] Step 9. Repeat steps 4 to 8 until all tasks are completed.

[0034] Specifically, in step 1, the thread states include idle, running, and waiting. Each thread in the thread pool is assigned a unique thread label V when initialized. The initial state S is idle, and the task category T is t Is a null value.

[0035] In step 2, the obtained pending tasks are divided into multiple task groups according to task relevance and dependency, and each task group has the same task category T m And priority P, priority P is the optimal solution already stored in the system, where P≤1 for urgent tasks.

[0036] Specifically, there are many methods for obtaining the optimal solution of the priority P, such as particle swarm algorithm, simulated annealing algorithm or ant colony algorithm, etc. Those skilled in the art can optimize according to experience and actual conditions, and there is no specific limitation.

[0037] If a new task is obtained when the threads have been allocated, it will be added to the existing task group according to its task relevance and dependency.

[0038] In step 4, the method for determining an urgent task is to traverse all tasks in the task list. If P≤1, it is an urgent task; if P>1, it is not an urgent task.

[0039] In step 5, the lowest priority task is stopped, the thread resources used by it are released and reallocated to the urgent task. The specific process of handling urgent tasks when there are no idle resources is as follows: Figure 2 shown.

[0040] Step 5.1: Find a task that is being executed and has the largest priority P value, and obtain its T m ;

[0041] Step 5.2, then according to T m Find the relevant task force;

[0042] Step 5.3, add the tasks in the task group back to the task queue;

[0043] Step 5.4, according to T t =T m , find all threads in the task group and get their thread labels V;

[0044] Step 5.5, finally, accurately find the threads through the thread label V, release the thread resources, assign the urgent tasks to these threads, update the task category of the threads to the task category of the urgent tasks, and ensure the centralized processing of the urgent tasks.

[0045] In step 5.1, find a task that is being executed and has the largest priority P value, and obtain its T m It is equivalent to finding a task that can be postponed, stopping the task group to which it belongs, and providing the thread resources used by the task group to the urgent task.

[0046] In step 5.3, the tasks in the task group are added back to the task queue to prevent task loss. When there are idle resources, they are taken out of the task queue according to the priority and task category and re-executed. The completed tasks are removed from the task group and will not be re-executed.

[0047] In step 5.4, according to T t =T m , find all threads in the task group and get their thread IDs V. Through the dual search mechanism of task category and thread ID, filter in a specific thread group, and then find the specific thread in the thread group, so as to limit the search scope to a smaller thread group or subset, avoid traversal of the entire thread pool, and thus reduce the search time.

[0048] In step 8, the thread is processed with related tasks. If there is no related task, the thread is released. m With S being the thread in the waiting state T t Same task.

[0049] If there is T m =T t If the task is a related task, the task is taken out of the queue and assigned to the thread, and the corresponding thread S is changed to the running state.

[0050] If there is no T m =T t task, release the thread, update S to idle and clear T t .

[0051] In steps 6 and 8, tasks and thread allocation are all allocated recursively or iteratively, and tasks of the same category are assigned to a thread group to ensure centralized processing of tasks and optimal utilization of resources.

[0052] Task allocation can use finer-grained indicators to allocate tasks, including real-time indicators such as CPU usage and memory availability. Technical personnel in this field can set them according to experience and actual conditions, and there is no specific limitation.

[0053] In this way, the implementation method of the present application improves the overall management efficiency by adding task identifiers to all threads, adopting a regionalized management method for thread tasks, and quickly locating and allocating thread resources through a dual search mechanism. When the tasks of each thread are completed, the related tasks are allocated first to ensure that the tasks in the same group are processed first, and the task allocation and resource management can be adjusted more efficiently in real time to ensure efficient resource utilization and normal system operation.

[0054] The present application is described in detail above in conjunction with specific implementation methods, but these descriptions cannot be understood as limiting the present application. For relevant technical personnel in the field, without departing from the spirit and scope of the present application, various equivalent replacements, modifications or improvements can be made to the technical solution and implementation methods of the present application, all of which fall within the scope of protection of the present application.

Claims

1. A multi-threaded task partition management method. It is characterized in that The steps of the multi-threaded task partition management method include: Create a thread pool containing multiple threads and assign each thread a unique thread label V, execution state S and task category T t ; Get pending tasks and assign them task category T m and priority P (P>0); Add the task to the task queue; Determine whether there are urgent tasks in the task queue; If there is an urgent task, stop the task with the lowest priority, release the thread resources it uses and reallocate them to the urgent task; If there is no urgent task, take the task from the task queue according to the priority, recursively assign the task to the thread, and update the thread status and task category at the same time. Threads of the same task category are assigned to a thread group. When a task is completed, update the thread status; Process related tasks for the thread. If related tasks continue to use the thread, release the thread if there is no related task, and update the thread status and task category. Repeat the above process until all tasks are completed.

2. The multi-threaded task partition management method according to claim 1, It is characterized in that The thread pool containing multiple threads is created, and each thread is assigned a unique thread label V, execution state S and task category T. t : Each thread in the thread pool is assigned a unique thread label V when initialized; the execution state S is initially idle, and also includes running and waiting states for real-time monitoring of resources and task status; the task category T t Used for thread regionalization management.

3. The multi-threaded task partition management method according to claim 1, It is characterized in that The task to be processed is obtained and the task category T is assigned to it m And priority P (P>0): The task category T m Used to group related tasks. Priority P is used to determine the order of task execution and the degree of urgency. When an urgent task is obtained, priority P ≤ 1.

4. The multi-threaded task partition management method according to claim 1, It is characterized in that The method for judging whether there is an urgent task in the task queue and the method for handling the same are as follows: Traverse all tasks in the task list. If P≤1, it is an urgent task. Then stop the task with the lowest priority, release its thread resources and reallocate them to the urgent task. If P>1, that is, it is not an urgent task, the task is taken out from the task queue according to the priority, the task is recursively assigned to the thread, the thread status and task category are updated, and threads of the same task category are assigned to a thread group.

5. The multi-threaded task partition management method according to claim 1, It is characterized in that The thread is processed with related tasks, and the related tasks continue to use the thread. If there is no related task, the thread is released, and the thread state and task category are updated, specifically: Check the task list for T m With S being the thread in the waiting state T t Same task: If there is T m =T t The task is a related task, the task is taken out of the queue and assigned to the thread, the task is executed, and the thread S changes to the running state; If there is no T m =T t task, then release S as the waiting thread resource, update its S to the idle state, and clear T t。 6. The multi-threaded task partition management method according to claim 4, It is characterized in that The method of stopping a task with the lowest priority, releasing its thread resources and reallocating them to the urgent task is as follows: Find a task that is being executed and has the largest priority P value (the larger the P value, the lower the priority), and then m , find the relevant task group, add the tasks in the task group back to the task queue, and then find the threads it uses through the dual search mechanism of task category and thread label, release these thread resources, and assign urgent tasks to these threads.

7. The multi-threaded task partition management method according to claim 4, It is characterized in that The process of taking tasks from the task queue according to the priority and recursively assigning tasks to threads is as follows: Tasks are taken out from the task queue in order of priority P from small to large, and the tasks are traversed in a recursive or iterative manner and assigned to threads to ensure that all tasks are processed until all tasks are assigned or there are no available threads.

Citation Information

Cited By

  • Pathological specimen auxiliary diagnosis system based on multi-thread control and task scheduling

    CN119883571A