A task management method, apparatus, electronic device, and storage medium

By implementing a task management method in computer devices, and using task description information and mutual exclusion information for bidirectional mutual exclusion comparison, the deadlock problem is solved, and task processing efficiency and thread utilization are improved.

CN115454660BActive Publication Date: 2026-07-17SUGON INFORMATION IND

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SUGON INFORMATION IND
Filing Date
2022-09-16
Publication Date
2026-07-17

AI Technical Summary

Technical Problem

In existing technologies, computer devices are prone to deadlock when processing multiple tasks, resulting in threads being occupied for a long time, low utilization, and low task processing efficiency.

Method used

By traversing the pending tasks in the message queue, a bidirectional mutual exclusion comparison is performed based on the task description information and mutual exclusion information. If there is no mutually exclusive task, it is executed through the thread pool. If there is a mutually exclusive task, a mutual exclusion tag or countdown timer is set, and it is compared with the mutual exclusion thread first, reducing the number of comparisons and improving efficiency.

Benefits of technology

This avoids deadlock, improves system security and thread utilization, and enhances task processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115454660B_ABST
    Figure CN115454660B_ABST
Patent Text Reader

Abstract

This invention discloses a task management method, which includes: traversing the pending tasks in a message queue, and performing a bidirectional mutual exclusion comparison between the current pending task and at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein the task information includes task description information and task mutual exclusion information; if there is no mutually exclusive task for the current pending task among the at least one running task, the current pending task is executed through a thread pool. The technical solution of this invention ensures that mutually exclusive tasks with mutual exclusion behavior do not run simultaneously, avoiding deadlock problems and improving system security performance; at the same time, it avoids threads being occupied for a long time, improving thread utilization and thus improving task processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a task management method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the continuous development of computer technology, the task processing capabilities of computer equipment, especially the concurrent processing capabilities of multiple tasks, have been rapidly improved, which has also placed higher demands on the task management capabilities of computer equipment.

[0003] In the prior art, computer devices add task requests to a message queue and execute each pending task in the message queue through multiple threads. In order to prevent multiple tasks from operating on the same resource at the same time, the resource is usually locked to ensure resource safety.

[0004] However, this task processing method results in threads being occupied for a long time, leading to low thread utilization and often causing deadlocks. At the same time, a large number of tasks are in a suspended waiting state, reducing task processing efficiency. Summary of the Invention

[0005] This invention provides a task management method, apparatus, electronic device, and storage medium to solve the deadlock problem caused by mutually exclusive tasks.

[0006] According to one aspect of the present invention, a task management method is provided, comprising:

[0007] Traverse the pending tasks in the message queue, and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information.

[0008] If there is no mutually exclusive task for the currently pending task among the at least one running tasks, then the currently pending task is executed through a thread pool.

[0009] After performing a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task, the process further includes: if there is a mutually exclusive task for the current pending task among the at least one running task, then setting a mutual exclusion tag for the current pending task and returning the current pending task to the message queue; in response to traversing the current pending task again, performing a bidirectional mutual exclusion comparison between the current pending task and running tasks in mutually exclusive threads and running tasks in non-mutual exclusion threads based on the mutual exclusion tag. Prioritizing comparison between the pending task and running tasks in mutually exclusive threads based on the mutual exclusion tag, if it is determined that the pending task and running tasks in mutually exclusive threads are still mutually exclusive, the pending task can be directly returned to the message queue, reducing the number of mutual exclusion comparisons and improving the efficiency of mutual exclusion comparison; simultaneously, comparing with running tasks in mutually exclusive threads and running tasks in non-mutual exclusion threads sequentially also ensures the accuracy of the mutual exclusion comparison results.

[0010] The step of performing a bidirectional mutual exclusion comparison between the current pending task and the at least one running task, based on the task information of the currently pending task and the task information of at least one running task, specifically includes: sorting the running tasks according to their task trigger types; wherein the task trigger types include background triggered tasks, timed triggered tasks, and user triggered tasks; and, according to the sorting results, sequentially performing a bidirectional mutual exclusion comparison between the current pending task and each of the running tasks. This ensures that the pending task is preferentially compared with running tasks of the same trigger type, further improving the efficiency of the mutual exclusion comparison.

[0011] The task management method further includes: in response to receiving a task request, creating a new task according to the task request; initializing the new task to obtain the task mutual exclusion information of the new task through a configuration file; and placing the initialized new task into the message queue. This not only reduces the amount of data transmitted for task requests but also avoids dependence on the mutual exclusion information of task requests. At the same time, the configuration file also improves the convenience of managing mutually exclusive tasks.

[0012] After performing a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task, the method further includes: if there is a mutual exclusion task for the current pending task among the at least one running task, then obtaining the predicted completion time of the mutual exclusion task; if the difference between the predicted traversal time of the message queue and the predicted completion time is greater than or equal to a first preset threshold, then sending the current pending task to a countdown queue and setting a countdown timer for the current pending task based on the predicted completion time; in response to detecting that the countdown timer has finished counting down, performing another bidirectional mutual exclusion comparison between the current pending task and the at least one running task; if there is no mutual exclusion task for the current pending task among the at least one running task, then executing the current pending task through a thread pool. By having idle threads appearing after the mutual exclusion task finishes executing the current pending task directly, compared to putting the current pending task back into the message queue to wait for the next traversal, the processing efficiency of the current pending task is greatly improved, thread utilization is increased, and the waiting time of idle threads is reduced.

[0013] After performing a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task, the method further includes: if there is a mutual exclusion task for the current pending task among the at least one running task, and the number of mutual exclusion tasks is less than or equal to a second preset threshold, then the current pending task is sent to the first thread where the first designated mutual exclusion task is located, so that the current pending task can wait to be executed in the first thread; in response to detecting that the first designated mutual exclusion task in the first thread has been processed, the current pending task and the at least one running task are again subjected to a bidirectional mutual exclusion comparison; if there is no mutual exclusion task for the current pending task among the at least one running task, then the current pending task is executed through the first thread. This improves the processing efficiency of pending tasks while reducing the idle waiting time of the first thread, thus increasing the utilization rate of the first thread.

[0014] After performing a bidirectional mutual exclusion comparison between the currently pending task and the at least one running task, the method further includes: if there is a mutual exclusion task for the currently pending task among the at least one running task, and the number of mutual exclusion tasks is less than or equal to a second preset threshold, then the currently pending task is sent to the second thread where the second specified mutual exclusion task is located, so that the currently pending task can wait to be executed in the second thread. This avoids the waiting of the pending task in the first thread causing the first thread to be occupied for a long time, thereby releasing the occupied first thread, which can then be allocated to other pending tasks in the message queue, further improving thread utilization.

[0015] According to another aspect of the present invention, a task management device is provided, comprising:

[0016] The mutual exclusion comparison execution module is used to traverse the pending tasks in the message queue and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information.

[0017] The task processing execution module is used to execute the currently pending task through a thread pool if there is no mutually exclusive task for the currently pending task among the at least one running tasks.

[0018] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0019] At least one processor; and

[0020] A memory communicatively connected to the at least one processor; wherein,

[0021] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the task management method according to any embodiment of the present invention.

[0022] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the task management method described in any embodiment of the present invention.

[0023] The technical solution of this invention traverses the tasks to be processed in the message queue and performs a bidirectional mutual exclusion comparison between the current task to be processed and the running task based on the task description information and task mutual exclusion information. If there is no mutually exclusive task for the current task to be processed among the running tasks, the current task to be processed is executed through the thread pool. This ensures that mutually exclusive tasks with mutual exclusion behavior do not run at the same time, avoids deadlock, and improves system security performance. At the same time, compared with locking device resources, it avoids threads being occupied for a long time, improves thread utilization, and thus improves task processing efficiency.

[0024] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0025] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0026] Figure 1 This is a flowchart of a task management method provided according to Embodiment 1 of the present invention;

[0027] Figure 2 This is a flowchart of a task management method provided according to Embodiment 2 of the present invention;

[0028] Figure 3 This is a flowchart of a task management method provided according to Embodiment 3 of the present invention;

[0029] Figure 4 This is a schematic diagram of the structure of a task management device according to Embodiment 4 of the present invention;

[0030] Figure 5 This is a schematic diagram of the structure of an electronic device that implements the task management method of this invention. Detailed Implementation

[0031] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0033] Example 1

[0034] Figure 1This is a flowchart of a task management method provided in Embodiment 1 of the present invention. This embodiment is applicable to avoiding the simultaneous execution of mutually exclusive tasks based on a bidirectional mutual exclusion comparison between tasks to be processed and running tasks. This method can be executed by a task management device, which can be implemented in hardware and / or software. The task management device can be configured in electronic devices such as servers, typically in a management server. Figure 1 As shown, the method includes:

[0035] S101. Traverse the pending tasks in the message queue, and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information.

[0036] The task information not only defines descriptive information such as the operation type, operation object, and system resources occupied by the current task, but also defines exclusionary information such as the operation type, operation object, and system resources occupied by other running tasks that cannot be executed when the current task is being processed. This is the mutual exclusion information of the current task. The task information can be provided by the requester of the task request. That is, when the requester issues a task request, the management server creates the processing task based on the task information provided by the requester.

[0037] For example, if the current task to be processed is node deletion, meaning the management server deletes the configuration information of a certain business server and no longer uses that business server as a node device, and the mutually exclusive task is node modification, meaning the management server modifies the configuration information of that business server, then obviously, a node deletion operation cannot be performed simultaneously with a node modification operation. The aforementioned node deletion operation will cause the node modification operation to fail to complete, leading to system failure or system alarm. Optionally, in this embodiment of the invention, the task type of the task to be processed is not specifically limited. In particular, in this embodiment of the invention, the node can be a business server connected to the management server, or it can be a functional module that the management server itself possesses.

[0038] When performing bidirectional mutual exclusion comparison, a run description list and a run mutual exclusion list can be drawn based on the task information of all running tasks. The run description list records the task description information of all running tasks. The task mutual exclusion information of the currently pending task is compared with the run description list to determine whether each running task is a mutual exclusion task of the currently pending task. The run mutual exclusion list records the task mutual exclusion information of all running tasks. The task description information of the currently pending task is compared with the run mutual exclusion list to determine whether the currently pending task is a mutual exclusion task of one or more running tasks.

[0039] If the mutual exclusion information of the current pending task includes the task description information of one or more running tasks, meaning that the execution of the aforementioned one or more running tasks will affect the normal operation of the current pending task, then the aforementioned one or more running tasks and the current pending task are mutually exclusive tasks. Similarly, if the mutual exclusion information of one or more running tasks includes the task description information of the current pending task, meaning that the execution of the current pending task will affect the execution of the aforementioned one or more running tasks, then the current pending task and the aforementioned one or more running tasks are also mutually exclusive tasks.

[0040] When performing a traversal operation in the message queue, the management server can sequentially traverse each pending task according to its pre-defined traversal logic. When an executable pending task is found, it sends the current pending task to the execution queue of the thread pool. The thread pool then manages the executable pending tasks by managing the execution queue to avoid blocking of executable tasks. Alternatively, the management server can perform a traversal operation based on idle threads in the thread pool, i.e., by obtaining an idle thread identifier sent by the thread pool or detecting the existence of an idle thread in the thread pool. When an executable pending task is found, the current pending task is sent to that idle thread, thus implementing a traversal operation based on idle threads. When no idle thread exists, the management server pauses the traversal operation to wait for a new idle thread to appear.

[0041] S102. If there is no mutually exclusive task for the currently pending task among the at least one running task, then the currently pending task is executed through a thread pool.

[0042] If the task mutual exclusion information of the currently pending task does not include any task description information of the running task, and the task mutual exclusion information of all running tasks does not include the task description information of the currently pending task, it indicates that there is no mutually exclusive task for the currently pending task among the running tasks. As described in the above technical solution, if the management server performs a traversal operation based on its own traversal logic, it sends the currently pending task to the execution queue of the thread pool, and the thread pool obtains the processing task through the execution queue. If the management server performs a traversal operation based on an idle thread, it directly sends the currently pending task to that idle thread.

[0043] If the mutual exclusion information of the currently pending task includes the task description information of any running task, or if the mutual exclusion information of any running task includes the task description information of the currently pending task, it indicates that there is a mutual exclusion task for the currently pending task among the running tasks. In this case, the currently pending task is put back into the message queue, and the process continues to iterate to obtain the next pending task. Specifically, the mutual exclusion information recorded in the task information can also include blocking mutual exclusion information and non-blocking mutual exclusion information. If there is a blocking mutual exclusion task for the currently pending task among the running tasks, and there is no non-blocking mutual exclusion task for the currently pending task, the currently pending task is put back into the message queue. If there is a non-blocking mutual exclusion task for the currently pending task among the running tasks, the currently pending task is deleted to avoid the currently pending task being in a meaningless waiting state when a non-blocking mutual exclusion task exists, and to avoid the accumulation of invalid processing tasks in the message queue.

[0044] Optionally, in this embodiment of the invention, after performing a bidirectional mutual exclusion comparison between the current task to be processed and the at least one running task based on the task information of the current task to be processed and the task information of at least one running task, the method further includes: if there is a mutually exclusive task of the current task to be processed among the at least one running task, then setting a mutual exclusion tag for the current task to be processed and putting the current task to be processed back into the message queue; in response to traversing the current task to be processed again, performing a bidirectional mutual exclusion comparison between the current task to be processed and the running tasks in the mutually exclusive thread and the running tasks in the non-mutual exclusion thread based on the mutual exclusion tag.

[0045] Specifically, since each task is executed through a thread in the thread pool, when adding a mutex label, the mutex task identifier and / or mutex thread identifier can be added to the mutex label. When the task to be processed is encountered again, it is compared with the running tasks in the mutex thread based on the mutex label. If it is determined that the current task to be processed is still mutually exclusive with the running tasks in the mutex thread, the current task to be processed can be directly put back into the message queue, reducing the number of mutual exclusion comparisons for the current task to be processed and improving the efficiency of mutual exclusion comparison. At the same time, comparing with the running tasks in the mutex thread and the running tasks in the non-mutex threads in turn ensures the accuracy of the bidirectional mutual exclusion comparison results.

[0046] Optionally, in this embodiment of the invention, the step of performing a bidirectional mutual exclusion comparison between the current task to be processed and the at least one running task based on the task information of the current task to be processed and the task information of at least one running task specifically includes: sorting each of the running tasks according to the task trigger type; wherein, the task trigger type includes background triggered tasks, timed triggered tasks, and user triggered tasks; and performing a bidirectional mutual exclusion comparison between the current task to be processed and each of the running tasks in sequence according to the sorting result.

[0047] Specifically, background-triggered tasks are tasks in which each business node requests task resources from the management server while processing tasks; the task initiator is each business node. Scheduled-triggered tasks are detection tasks initiated by the management server itself; the task initiator is the management server. User-triggered tasks are task requests initiated by user terminals. Obviously, tasks with the same trigger type are more likely to be mutually exclusive. Therefore, when comparing the currently pending task with each running task, the running tasks can be sorted based on the trigger type of the currently pending task. This allows the currently pending task to be prioritized for bidirectional mutual exclusion comparison with running tasks of the same trigger type, further improving the efficiency of bidirectional mutual exclusion comparison.

[0048] Optionally, in this embodiment of the invention, the task management method further includes: in response to receiving a task request, creating a new task according to the task request; initializing the new task to obtain the task mutual exclusion information of the new task through a configuration file; and placing the initialized new task into the message queue.

[0049] Specifically, when the management server receives a task request, it directly obtains the task description information based on the request, such as the trigger type, operation type, operation object, and system resources occupied by the current task. After obtaining the task description information, it retrieves the matching mutual exclusion information from the configuration file based on the above description information. For example, if the current task request is to modify the configuration information of node A, the configuration file can determine that the mutual exclusion behavior corresponding to the modification operation is a deletion operation. Therefore, the corresponding mutual exclusion information is to delete node A. In this way, the mutual exclusion information for each task to be processed can be obtained through the configuration file. Compared to the mutual exclusion information being provided synchronously by the sender of the task request, this not only reduces the amount of data transmitted in the task request but also avoids dependence on the mutual exclusion information of the task request. At the same time, the configuration file also improves the convenience of managing mutually exclusive tasks.

[0050] The technical solution of this invention traverses the tasks to be processed in the message queue and performs a bidirectional mutual exclusion comparison between the current task to be processed and the running task based on the task description information and task mutual exclusion information. If there is no mutually exclusive task for the current task to be processed among the running tasks, the current task to be processed is executed through the thread pool. This ensures that mutually exclusive tasks with mutual exclusion behavior do not run at the same time, avoids deadlock, and improves system security performance. At the same time, compared with locking device resources, it avoids threads being occupied for a long time, improves thread utilization, and thus improves task processing efficiency.

[0051] Example 2

[0052] Figure 2 This is a flowchart of a task management method provided in Embodiment 2 of the present invention. The relationship between this embodiment and the above embodiments is that if there is a mutually exclusive task among the running tasks that is currently pending, the predicted completion time of the mutually exclusive task is obtained, and the currently pending task is processed based on the predicted completion time. Figure 2 As shown, the method includes:

[0053] S201. Traverse the pending tasks in the message queue, and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information.

[0054] S202. If there is a mutually exclusive task of the currently pending task among the at least one running task, then obtain the predicted completion time of the mutually exclusive task.

[0055] The predicted completion time is calculated based on the task trigger type (e.g., background triggered task, timed triggered task, and user triggered task) and / or task operation type (e.g., node modification operation, node addition operation, and node deletion operation), using the current moment as the starting point. If the current task corresponds to only one mutually exclusive task, the predicted completion time is the time required for that mutually exclusive task to complete. If the current task corresponds to multiple mutually exclusive tasks, the predicted completion time is the time required for all mutually exclusive tasks to complete, which is the maximum value among the completion times of each mutually exclusive task. The predicted completion time value indicates that all mutually exclusive tasks in the currently running task have completed after the above time value.

[0056] S203. If the difference between the predicted traversal time and the predicted completion time of the message queue is greater than or equal to the first preset threshold, then the current task to be processed is sent to the countdown queue, and a countdown timer is set for the current task to be processed.

[0057] The predicted traversal time is the time required to complete one traversal of all pending tasks in the message queue. Since the pending tasks and running tasks need to be compared bidirectionally during the traversal, the predicted traversal time is positively correlated with both the number of running tasks and the number of pending tasks. After obtaining the predicted traversal time based on the number of running tasks and pending tasks, the difference between the predicted traversal time and the predicted completion time is compared with a first preset threshold. If the difference between the predicted traversal time and the predicted completion time is large, i.e. greater than the first preset threshold, it indicates that it takes a long time to traverse the pending task again after putting it back into the message queue. After a short time (i.e., the predicted completion time), all the mutual exclusion tasks in the currently running tasks have finished running, and the pending task can be directly executed by the idle thread that appears after the mutual exclusion tasks have finished running.

[0058] S204. In response to detecting that the countdown timer has finished counting down, the current task to be processed and the at least one running task are compared again in a bidirectional mutual exclusion manner.

[0059] When the countdown is complete, the tasks to be processed need to be compared with each running task again. Therefore, one or more mutually exclusive tasks may experience running delays, resulting in failure to complete. At the same time, during the countdown, one or more threads may have changed running tasks, and the new running tasks may have created new mutual exclusions with the tasks to be processed. This avoids deadlocks caused by running delays of the original mutually exclusive tasks and the emergence of new mutually exclusive tasks.

[0060] S205. If there is no mutually exclusive task for the currently pending task among the at least one running task, then the currently pending task is executed through a thread pool.

[0061] In the technical solution of this invention, if there is a mutex task for the currently pending task in the running task, and the difference between the predicted traversal time of the message queue and the predicted completion time of the mutex task is greater than or equal to a first preset threshold, then the currently pending task is sent to the countdown queue. When the countdown is completed and the bidirectional mutual exclusion comparison confirms that there is no mutex task, the currently pending task is executed through the thread pool. This allows the idle thread that appears after the mutex task finishes running to directly execute the pending task. Compared with putting the currently pending task back into the message queue to wait for the next traversal, this greatly improves the processing timeliness of the currently pending task, increases thread utilization, and reduces the waiting time of idle threads.

[0062] Example 3

[0063] Figure 3This is a flowchart of a task management method provided in Embodiment 3 of the present invention. The relationship between this embodiment and the above embodiments is that if the number of mutex tasks currently pending in the running task is less than or equal to a second preset threshold, then the currently pending task is sent to the thread where the specified mutex task is located to wait for execution. Figure 3 As shown, the method includes:

[0064] S301. Traverse the pending tasks in the message queue, and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information.

[0065] S302. If there is a mutual exclusion task of the current task to be processed in the at least one running task, and the number of mutual exclusion tasks is less than or equal to the second preset threshold, then the current task to be processed is sent to the first thread where the first specified mutual exclusion task is located, so that the current task to be processed can wait to be executed in the first thread; execute S305.

[0066] If a mutex task exists within the running tasks that is currently pending, the current pending task must wait for that mutex task to finish before it can run. Therefore, when the second preset threshold equals 1 (i.e., when there is only one mutex task), the current pending task is sent to the thread containing that mutex task and queued there, waiting for that thread to complete its execution. When the second preset threshold is greater than 1 (e.g., when there are two mutex tasks), the current pending task can be sent to the thread containing the mutex task with the longest predicted completion time (i.e., the one that finishes latest) based on the predicted completion time of each mutex task, so that the current pending task queues there and waits for that thread to complete its execution. Specifically, after sending the current pending task to a matching thread to queue it, the management server continues to iterate through the other pending tasks in the message queue.

[0067] S303. If there is a mutually exclusive task of the currently pending task in the at least one running task, and the number of mutually exclusive tasks is greater than the second preset threshold, then the currently pending task is put back into the message queue.

[0068] When the number of mutex tasks is large, i.e. greater than the second preset threshold, it is not possible to accurately determine which thread the current task to be processed is executing in. Moreover, the predicted completion time is itself a predicted value, which has a certain prediction error. Among the multiple predicted completion times corresponding to multiple mutex tasks, the possibility of prediction error is increased. Therefore, the current task to be processed is put back into the message queue to avoid assigning the current task to a mismatched thread, which would cause the current task to wait for too long.

[0069] S304. If there is no mutually exclusive task for the currently pending task among the at least one running task, then the currently pending task is executed through a thread pool.

[0070] If there are no mutually exclusive tasks, the currently pending task can be executed by any idle thread in the thread pool.

[0071] S305. In response to detecting that the first specified mutex task in the first thread has been processed, the current task to be processed and the at least one running task are compared again in a bidirectional mutual exclusion manner.

[0072] When the first specified mutex task in the first thread is detected to have completed processing, other threads outside the first thread may have changed their running tasks. The changed running tasks may have created new mutual exclusions with the current task to be processed. At the same time, there may be task processing delays in other threads outside the first thread, which may cause the original mutex task that should have finished running to not have finished running, resulting in mutual exclusion with the current task to be processed. Therefore, after the first specified mutex task in the first thread is completed, before executing the current task to be processed, it is necessary to perform a bidirectional mutual exclusion comparison between the current task to be processed and each running task again.

[0073] S306. If there is no mutually exclusive task for the currently pending task among the at least one running tasks, then the currently pending task is executed through the first thread.

[0074] After performing a bidirectional mutual exclusion comparison between the current pending task and each running task, if no mutually exclusive task exists, the current pending task can be executed directly by the first thread. This improves the processing efficiency of the pending task, reduces the idle waiting time of the first thread, and increases the utilization rate of the first thread.

[0075] S307. If there is a mutual exclusion task of the current task to be processed in the at least one running task, and the number of mutual exclusion tasks is less than or equal to the second preset threshold, then the current task to be processed is sent to the second thread where the second specified mutual exclusion task is located, so that the current task to be processed can wait to be executed in the second thread.

[0076] As described in the above technical solution, if a new running task is introduced in another thread and a new mutual exclusion exists between the new running task and the current task to be processed, or if the original mutual exclusion task in another thread has not finished running and the original mutual exclusion task and the current task to be processed still exist mutually exclusive, then the current task to be processed is sent to the second thread where the longest-running mutual exclusion task (i.e., the second specified mutual exclusion task) is located. This avoids the current task to be processed waiting in the first thread, which would cause the first thread to be occupied for a long time. This releases the occupied first thread, which can then be allocated to other tasks to be processed in the message queue, further improving thread utilization.

[0077] S308. If there is a mutually exclusive task of the currently pending task in the at least one running task, and the number of mutually exclusive tasks is greater than the second preset threshold, then the currently pending task is put back into the message queue.

[0078] In the technical solution of this invention embodiment, if there is a mutually exclusive task of the currently pending task in the running task, and the number of mutually exclusive tasks is less than or equal to a second preset threshold, then the currently pending task is sent to the first thread where the first specified mutually exclusive task is located, so that the currently pending task can wait to be executed in the first thread. When the first specified mutually exclusive task is completed, the currently pending task and the running task are compared again for mutual exclusion. If there is no mutually exclusive task, the currently pending task is executed by the first thread. This improves the processing efficiency of the pending task, reduces the idle waiting time of the first thread, and improves the utilization rate of the first thread.

[0079] Example 4

[0080] Figure 4 This is a structural block diagram of a task management device provided in Embodiment 4 of the present invention. The device specifically includes:

[0081] The mutual exclusion comparison execution module 401 is used to traverse the pending tasks in the message queue and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information.

[0082] The task processing execution module 402 is used to execute the current task to be processed through a thread pool if there is no mutually exclusive task for the current task to be processed among the at least one running tasks.

[0083] The technical solution of this invention traverses the tasks to be processed in the message queue and performs a bidirectional mutual exclusion comparison between the current task to be processed and the running task based on the task description information and task mutual exclusion information. If there is no mutually exclusive task for the current task to be processed among the running tasks, the current task to be processed is executed through the thread pool. This ensures that mutually exclusive tasks with mutual exclusion behavior do not run at the same time, avoids deadlock, and improves system security performance. At the same time, compared with locking device resources, it avoids threads being occupied for a long time, improves thread utilization, and thus improves task processing efficiency.

[0084] Optionally, the task management device also includes:

[0085] The mutual exclusion label setting module is used to set a mutual exclusion label for the current task to be processed if there is a mutual exclusion task for the current task to be processed in the at least one running task, and put the current task to be processed back into the message queue.

[0086] The tag comparison execution module is used to, in response to the current task to be processed being traversed again, perform bidirectional mutual exclusion comparison between the current task to be processed and the running tasks in the mutual exclusion thread and the running tasks in the non-mutual exclusion thread based on the mutual exclusion tag.

[0087] Optionally, the mutual exclusion comparison execution module 401 is specifically used to sort each of the running tasks according to the task triggering type; wherein, the task triggering type includes background triggered tasks, timed triggered tasks and user triggered tasks; according to the sorting result, the current task to be processed is sequentially compared with each of the running tasks in a bidirectional mutual exclusion manner.

[0088] Optionally, the task management device also includes:

[0089] The new task creation module is used to respond to a task request, create a new task according to the task request, initialize the new task to obtain the task mutual exclusion information of the new task through the configuration file, and put the initialized new task into the message queue.

[0090] Optionally, the task management device also includes:

[0091] The prediction completion time acquisition module is used to: acquire the predicted completion time of the mutex task if there is a mutex task of the current pending task among the at least one running task; if the difference between the predicted traversal time of the message queue and the predicted completion time is greater than or equal to a first preset threshold, send the current pending task to a countdown queue and set a countdown timer for the current pending task according to the predicted completion time; in response to detecting that the countdown timer has finished counting down, perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task again; if there is no mutex task of the current pending task among the at least one running task, execute the current pending task through a thread pool.

[0092] Optionally, the task management device also includes:

[0093] The designated thread sending module is configured to, if there is a mutex task for the currently pending task among the at least one running task, and the number of mutex tasks is less than or equal to a second preset threshold, send the currently pending task to the first thread where the first designated mutex task is located, so that the currently pending task can wait to be executed in the first thread; in response to detecting that the first designated mutex task in the first thread has been processed, perform a bidirectional mutual exclusion comparison between the currently pending task and the at least one running task again; if there is no mutex task for the currently pending task among the at least one running task, then execute the currently pending task through the first thread.

[0094] Optionally, the designated thread sending module is further configured to send the current task to the second thread where the second designated mutual exclusion task is located if there is a mutual exclusion task of the current task to be processed in the at least one running task, and the number of mutual exclusion tasks is less than or equal to a second preset threshold, so that the current task to be processed can wait to be executed in the second thread.

[0095] The above-described apparatus can execute the task management method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method. Technical details not described in detail in this embodiment can be found in the task management method provided in any embodiment of the present invention.

[0096] Example 5

[0097] Figure 5A schematic diagram of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0098] like Figure 5 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0099] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0100] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as task management methods.

[0101] In some embodiments, the task management method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on a heterogeneous hardware accelerator via ROM and / or a communication unit. When the computer program is loaded into RAM and executed by a processor, one or more steps of the task management method described above may be performed. Alternatively, in other embodiments, the processor may be configured to perform the task management method by any other suitable means (e.g., by means of firmware).

[0102] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0103] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0104] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0105] To provide user interaction, the systems and techniques described herein can be implemented on a heterogeneous hardware accelerator, which includes: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the heterogeneous hardware accelerator. Other types of devices can also be used to provide user interaction; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or haptic feedback); and input from the user can be received in any form (including sound input, voice input, or haptic input).

[0106] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0107] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0108] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0109] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A task management method, characterized in that, include: Traverse the pending tasks in the message queue, and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information. If there is no mutually exclusive task for the currently pending task among the at least one running tasks, then the currently pending task is executed through a thread pool. The process further includes, after performing a bidirectional mutually exclusive comparison between the current task to be processed and the at least one running task based on the task information of the current task to be processed and the task information of at least one running task: If there is a mutual exclusion task of the currently pending task in the at least one running task, and the number of mutual exclusion tasks is less than or equal to the second preset threshold, then the currently pending task is sent to the first thread where the first specified mutual exclusion task is located, so that the currently pending task can wait to be executed in the first thread. In response to detecting that the first specified mutex task in the first thread has been processed, the current task to be processed and the at least one running task are compared again for bidirectional mutual exclusion. If there is no mutually exclusive task for the currently pending task among the at least one running tasks, then the currently pending task is executed through the first thread.

2. The method according to claim 1, characterized in that, After performing a bidirectional mutually exclusive comparison between the current task to be processed and the at least one running task based on the task information of the current task to be processed and the task information of at least one running task, the method further includes: If there is a mutually exclusive task for the currently pending task among the at least one running task, then a mutual exclusion label is set for the currently pending task, and the currently pending task is put back into the message queue. In response to the current task to be processed being traversed again, the current task to be processed is compared with the running tasks in the mutual exclusion thread and the running tasks in the non-mutual exclusion thread in a bidirectional mutual exclusion comparison based on the mutual exclusion label.

3. The method according to claim 1, characterized in that, The step of performing a bidirectional mutually exclusive comparison between the current task to be processed and the at least one running task, based on the task information of the current task to be processed and the task information of at least one running task, specifically includes: The running tasks are sorted according to their trigger types; wherein, the trigger types include background triggered tasks, timed triggered tasks, and user triggered tasks. Based on the sorting results, the currently pending task is compared with each of the running tasks in a bidirectional mutually exclusive manner.

4. The method according to claim 1, characterized in that, The task management method also includes: In response to receiving a task request, a new task is created based on the task request; The new task is initialized to obtain the task mutual exclusion information of the new task through the configuration file; Place the newly initialized task into the message queue.

5. The method according to claim 1, characterized in that, After performing a bidirectional mutually exclusive comparison between the current task to be processed and the at least one running task based on the task information of the current task to be processed and the task information of at least one running task, the method further includes: If there is a mutually exclusive task of the currently pending task among the at least one running task, then obtain the predicted completion time of the mutually exclusive task; If the difference between the predicted traversal time of the message queue and the predicted completion time is greater than or equal to the first preset threshold, the current task to be processed is sent to the countdown queue, and a countdown timer is set for the current task to be processed according to the predicted completion time. In response to detecting that the countdown timer has finished counting down, the current task to be processed and the at least one running task are compared again in a bidirectional mutual exclusion manner; If there is no mutually exclusive task for the currently pending task among the at least one running tasks, then the currently pending task is executed through a thread pool.

6. The method according to claim 1, characterized in that, After performing another bidirectional mutual exclusion comparison between the currently pending task and the at least one running task, the method further includes: If there is a mutual exclusion task for the currently pending task in the at least one running task, and the number of mutual exclusion tasks is less than or equal to a second preset threshold, then the currently pending task is sent to the second thread where the second specified mutual exclusion task is located, so that the currently pending task can wait to be executed in the second thread.

7. A task management device, characterized in that, include: The mutual exclusion comparison execution module is used to traverse the pending tasks in the message queue and perform a bidirectional mutual exclusion comparison between the current pending task and the at least one running task based on the task information of the current pending task and the task information of at least one running task; wherein, the task information includes task description information and task mutual exclusion information. The task processing and execution module is used to execute the currently pending task through a thread pool if there is no mutually exclusive task for the currently pending task among the at least one running tasks. The task management device further includes: The designated thread sending module is used to send the current task to the first thread where the first designated mutual exclusion task is located if there is a mutual exclusion task of the current task to be processed in the at least one running task and the number of mutual exclusion tasks is less than or equal to a second preset threshold, so that the current task to be processed can wait to be executed in the first thread. In response to detecting that the first specified mutex task in the first thread has been processed, the current task to be processed and the at least one running task are compared again for bidirectional mutual exclusion. If there is no mutually exclusive task for the currently pending task among the at least one running tasks, then the currently pending task is executed through the first thread.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the task management method according to any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the task management method according to any one of claims 1-6.