A coroutine scheduling method, device, computer program product and medium

By judging the emergency scheduling conditions of coroutines and urgent scheduling, the problem that coroutines in the existing technology is difficult to respond to urgent tasks, and the timely completion of tasks and accelerated progress is achieved.

CN119127450BActive Publication Date: 2025-02-25INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411621843.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-14
Publication Date
2025-02-25
Estimated Expiration
2044-11-14

AI Technical Summary

Technical Problem

The existing coroutine scheduling methods are difficult to effectively respond to the urgent execution needs of tasks, resulting in the inability to complete tasks in a timely manner, affecting the execution of other tasks.

Method used

By determining whether the coroutine meets the emergency scheduling conditions, including the non-empty tasks of the task and/or the task completion degree reaches the preset threshold, if it is satisfied, the coroutine is urgently scheduled and the scheduling sequence is determined based on its emergency scheduling times.

Benefits of technology

It realizes the timely and effective response to the task's emergency processing needs, speeds up the task completion progress, and ensures that the task is completed on time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127450B_ABST
    Figure CN119127450B_ABST
Patent Text Reader

Abstract

The present invention discloses a coroutine scheduling method, device, computer program product and medium, which relate to the field of computer technology, including: in response to the coroutine giving up the execution right due to task blocking, judging whether the coroutine meets the emergency scheduling condition; the emergency scheduling condition includes: other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold; if the coroutine meets the emergency scheduling condition, the coroutine is urgently scheduled. The method determines the actual execution demand of the task based on the completion degree of the task and / or whether other tasks that depend on the task are empty, can respond to the actual emergency execution demand of the task, and speed up the progress of task completion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a coroutine scheduling method, device, computer program product and medium. Background Art

[0002] Coroutines are also called user-mode threads. The scheduling of coroutines is controlled by the user mode. The scheduling of coroutines can be divided into preemptive scheduling and cooperative scheduling. Under preemptive scheduling, the priority of the coroutine is usually set in advance, and the priority of the coroutine is related to the priority of the task for which the coroutine is responsible. The higher the priority of the task for which the coroutine is responsible, the higher the priority of the coroutine. In the actual execution process, if all coroutines are in an executable state, the coroutine with a high priority is executed first. Preemptive scheduling can give certain tasks the privilege of priority execution, but the coroutines are prioritized and preemptively scheduled based on the priority of the coroutines. It is not always possible to achieve reasonable scheduling of the coroutines and effectively respond to the actual execution requirements of the tasks. For example, a task that actually needs to be executed in a timely manner cannot be executed in a timely manner due to the low priority of the coroutine responsible for the task, thereby delaying the progress of the task completion and even affecting the execution of other tasks. Therefore, how to solve the above-mentioned technical defects has become a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention

[0003] The purpose of the present invention is to provide a coroutine scheduling method, device, computer program product and medium, which can respond to the actual urgent execution needs of the task and speed up the progress of task completion.

[0004] In order to solve the above technical problems, the present invention provides a coroutine scheduling method, comprising:

[0005] In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine meets an emergency scheduling condition; the emergency scheduling condition includes: other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0006] If the coroutine meets the emergency scheduling condition, the coroutine is urgently scheduled.

[0007] In some embodiments, urgently scheduling the coroutine includes:

[0008] Determine the scheduling order of the coroutine according to the number of emergency scheduling of the coroutine; wherein, the more the number of emergency scheduling of the coroutine is, the higher the scheduling order of the coroutine is;

[0009] The coroutines are scheduled according to the scheduling order.

[0010] In some embodiments, determining the scheduling order of the coroutines according to the number of emergency scheduling of the coroutines includes:

[0011] According to the number of emergency scheduling of the coroutine, the position of the identifier corresponding to the coroutine in the coroutine queue array is determined, and the identifier corresponding to the coroutine is inserted into the determined position to schedule the coroutine according to the position of the identifier corresponding to the coroutine in the coroutine queue array.

[0012] In some embodiments, determining the position of the identifier corresponding to the coroutine in the coroutine queue array according to the number of emergency dispatches of the coroutine, and inserting the identifier corresponding to the coroutine at the determined position includes:

[0013] According to the number of emergency dispatches of the coroutine, the position of the pointer of the coroutine description structure of the coroutine in the coroutine queue array is determined, and the pointer of the coroutine description structure of the coroutine is inserted into the determined position, wherein the coroutine description structure is used to describe the information and status of the coroutine.

[0014] In some embodiments, according to the number of emergency dispatches of the coroutine, before determining the position of the identifier corresponding to the coroutine in the coroutine queue array, the method further includes:

[0015] Determine whether the number of emergency dispatches of the coroutine after adding one is greater than the maximum value within the allowed range;

[0016] If not, the emergency dispatch times of the coroutine are increased by one, and the position of the identifier corresponding to the coroutine in the coroutine queue array is determined according to the increased emergency dispatch times.

[0017] In some embodiments, it also includes:

[0018] If the number of emergency scheduling times of the coroutine plus one is greater than the maximum value within the allowed range, the number of emergency scheduling times of the coroutine is set to the default value, and the coroutine is linked to the end of the coroutine queue; the coroutine queue is used to manage coroutines that are blocked during task execution and newly created coroutines.

[0019] In some embodiments, it also includes:

[0020] Determine whether the coroutine queue array is empty;

[0021] If it is empty, select elements from the coroutine queue and add them to the coroutine queue array.

[0022] In some embodiments, selecting an element from a coroutine queue and adding it to the coroutine queue array includes:

[0023] A target number of elements are selected from the head of the coroutine queue and added to the coroutine queue array; the target number is equal to the size of the coroutine queue array.

[0024] In some embodiments, it also includes:

[0025] If the coroutine meets the emergency dispatch condition, an emergency dispatch flag is set for the coroutine.

[0026] In some embodiments, it also includes:

[0027] Create a new coroutine and link it to the end of the coroutine queue.

[0028] In some embodiments, it also includes:

[0029] In response to the coroutine relinquishing the execution right due to completion of the assigned task, the coroutine is destroyed.

[0030] In some embodiments, it also includes:

[0031] In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine is set with a high execution priority flag;

[0032] If the coroutine is set with a high execution priority flag, the coroutine is urgently scheduled.

[0033] In some embodiments, it also includes:

[0034] If the coroutine is not set with a high execution priority flag and the coroutine does not meet the emergency scheduling condition, the coroutine is linked to the end of the coroutine queue.

[0035] In order to solve the above technical problem, the present invention also provides a computer program product, including a computer program / instruction, which implements the steps of the coroutine scheduling method described above when executed by a processor.

[0036] In order to solve the above technical problems, the present invention further provides a coroutine scheduling device, comprising:

[0037] Memory for storing computer programs;

[0038] A processor is used to implement the steps of the coroutine scheduling method as described above when executing the computer program.

[0039] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the coroutine scheduling method as described above are implemented.

[0040] In order to solve the above technical problems, the present invention also provides a coroutine scheduling system, comprising:

[0041] A judgment unit, configured to judge whether the coroutine satisfies an emergency scheduling condition in response to the coroutine giving up the execution right due to task blocking; the emergency scheduling condition includes: other tasks dependent on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0042] The scheduling unit is used to urgently schedule the coroutine if the coroutine meets the emergency scheduling condition.

[0043] The coroutine scheduling method provided by the present invention includes: in response to the coroutine giving up the execution right due to task blocking, judging whether the coroutine meets the emergency scheduling condition; the emergency scheduling condition includes: other tasks dependent on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold; if the coroutine meets the emergency scheduling condition, the coroutine is urgently scheduled.

[0044] It can be seen that the coroutine scheduling method provided by the present invention determines the actual execution requirements of a task based on the degree of completion of the task and / or whether other tasks that depend on the task are empty. The degree of completion of a task reaches a preset threshold and / or other tasks that depend on the task are not empty, which can reflect that the task actually has an emergency processing requirement. Therefore, when the degree of completion of a task reaches a preset threshold and / or other tasks that depend on the task are not empty, the coroutine responsible for the task is urgently scheduled, which can respond to the actual emergency processing requirements of the task in a timely and effective manner and speed up the completion of the task.

[0045] The coroutine scheduling device, computer program product, computer-readable storage medium and coroutine scheduling system provided by the present invention all have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the prior art and the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0047] Figure 1 A flowchart of a coroutine scheduling method provided by an embodiment of the present invention;

[0048] Figure 2 A thread schematic diagram provided by an embodiment of the present invention;

[0049] Figure 3 A schematic diagram of a coroutine scheduling device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0050] The core of the present invention is to provide a coroutine scheduling method, device, computer program product and medium, which can respond to the actual urgent execution needs of the task and speed up the progress of task completion.

[0051] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0052] Please refer to Figure 1 , Figure 1 A flowchart of a coroutine scheduling method provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method includes:

[0053] S101: In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine meets the emergency scheduling condition; the emergency scheduling condition includes: other tasks dependent on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0054] S102: If the coroutine meets the emergency dispatch condition, the coroutine is urgently dispatched.

[0055] The coroutine scheduling method provided in this embodiment is implemented by a coroutine scheduling system. Figure 2As shown, a coroutine system can be constructed between threads, and the coroutine system includes coroutine scheduling and several coroutines. When the coroutine relinquishes the execution right due to task blocking during the execution of the task, it is determined whether the coroutine meets the emergency scheduling condition. The emergency scheduling condition includes that other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold. The task that depends on the coroutine is responsible for executing refers to the task that needs to be executed after the task that the coroutine is responsible for executing is executed. The completion of the task that the coroutine is responsible for executing affects other subsequent tasks that depend on the task. Therefore, the fact that other tasks that depend on the task that the coroutine is responsible for executing are not empty can reflect to a certain extent that the task that the coroutine is responsible for executing has the need for emergency processing. The completion degree of the task that the coroutine is responsible for executing reaches the preset threshold, but the task cannot be completed due to task blocking, which can also reflect that the task that the coroutine is responsible for executing has the need for emergency processing. Therefore, the fact that other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches the preset threshold are used as emergency scheduling conditions. By judging whether the coroutine meets the emergency scheduling conditions, it can be determined whether the task that the coroutine is responsible for executing has the need for emergency processing. If the coroutine meets the emergency scheduling conditions, the coroutine is urgently scheduled to speed up the completion of the task that the coroutine is responsible for executing.

[0056] In some embodiments, it also includes:

[0057] If the coroutine meets the emergency dispatch condition, an emergency dispatch flag is set for the coroutine.

[0058] If the coroutine is set with an urgent dispatch flag, the coroutine is urgently dispatched.

[0059] In some embodiments, urgently scheduling the coroutine includes:

[0060] Determine the scheduling order of the coroutine according to the number of emergency scheduling of the coroutine; wherein, the more the number of emergency scheduling of the coroutine is, the higher the scheduling order of the coroutine is;

[0061] The coroutines are scheduled according to the scheduling order.

[0062] Coroutines can be urgently scheduled multiple times. If the task that the coroutine is responsible for executing is not completed, the more times the coroutine is urgently scheduled, the more urgent the need to complete the task is. Therefore, the more times the coroutine is urgently scheduled, the higher the scheduling order of the coroutine is, so that the coroutine can be scheduled faster, thereby speeding up the completion of the task that the coroutine is responsible for executing.

[0063] In some embodiments, determining the scheduling order of the coroutines according to the number of emergency scheduling of the coroutines includes:

[0064] According to the number of emergency scheduling of the coroutine, the position of the identifier corresponding to the coroutine in the coroutine queue array is determined, and the identifier corresponding to the coroutine is inserted into the determined position to schedule the coroutine according to the position of the identifier corresponding to the coroutine in the coroutine queue array.

[0065] This embodiment sorts the coroutines by an array. The closer the position of the identifier corresponding to the coroutine in the coroutine queue array is, the earlier the coroutine can be scheduled.

[0066] In some embodiments, determining the position of the identifier corresponding to the coroutine in the coroutine queue array according to the number of emergency dispatches of the coroutine, and inserting the identifier corresponding to the coroutine at the determined position includes:

[0067] According to the number of emergency dispatches of the coroutine, the position of the pointer of the coroutine description structure of the coroutine in the coroutine queue array is determined, and the pointer of the coroutine description structure of the coroutine is inserted into the determined position, wherein the coroutine description structure is used to describe the information and status of the coroutine.

[0068] In this embodiment, the identifier corresponding to the coroutine is a pointer to the coroutine description structure of the coroutine. The coroutine description structure is a coroutine description data structure, which is used to describe the information and status of the coroutine. The elements in the coroutine queue array are pointers to the coroutine description structure. The coroutine corresponding to the element at the head of the coroutine queue array is given priority as the incoming coroutine to obtain the execution right during the next scheduling. After the coroutine corresponding to the element at the head of the coroutine queue array obtains the execution right, the head element is removed from the coroutine queue array, and the other elements in the coroutine queue array are moved forward by one position. In addition, the element at the head of the coroutine queue is selected and added to the tail of the coroutine queue array.

[0069] If the coroutine meets the emergency dispatch condition, the position of the pointer of the coroutine description structure of the coroutine in the coroutine queue array is determined according to the number of emergency dispatches of the coroutine, and the pointer of the coroutine description structure of the coroutine is inserted into the determined position. When the pointer of the coroutine description structure of the coroutine is moved from the inserted position to the head of the coroutine queue array, the coroutine can be preferentially used as the incoming coroutine to obtain the execution right in the next dispatch.

[0070] For example, if the size of the coroutine queue array is 64, the position of the pointer of the coroutine description structure of the coroutine in the coroutine queue array can be determined according to 2^(6-N). N is the number of emergency dispatches of the coroutine. The value range of N is 0, 1, 2, 3. If N is 1, the pointer of the coroutine description structure of the coroutine is inserted at the 32nd position in the coroutine queue array. If N is 2, the pointer of the coroutine description structure of the coroutine is inserted at the 16th position in the coroutine queue array. If N is 3, the pointer of the coroutine description structure of the coroutine is inserted at the 8th position in the coroutine queue array.

[0071] Among them, as shown in Table 1, the coroutine description structure may include coroutine ID, task ID, dependency, who is dependent, number of dispatches, task completion, the number of emergency dispatches, and emergency dispatch identifier. The coroutine ID is the unique identifier of the coroutine. Each coroutine has a unique coroutine ID after being created. The task ID is the identifier of the task assigned to the coroutine. Dependence refers to which task is executed after the task assigned to the coroutine is executed, and who is dependent refers to which task is executed after the task assigned to the coroutine is executed. The number of dispatches is the total number of times the coroutine is dispatched. Task completion is an attribute of the coroutine, which accompanies the entire life cycle and is managed by the coroutine itself. The number of emergency dispatches is the number of emergency dispatches mentioned above. The default value of the number of emergency dispatches field is 0. The default value of the emergency dispatch identifier field is 0. If the value of the emergency dispatch identifier is 1, the emergency dispatch identifier is set for the table coroutine.

[0072] Table 1

[0073]

[0074] In some embodiments, according to the number of emergency dispatches of the coroutine, before determining the position of the identifier corresponding to the coroutine in the coroutine queue array, the method further includes:

[0075] Determine whether the number of emergency dispatches of the coroutine after adding one is greater than the maximum value within the allowed range;

[0076] If not, the emergency dispatch times of the coroutine are increased by one, and the position of the identifier corresponding to the coroutine in the coroutine queue array is determined according to the increased emergency dispatch times.

[0077] In some embodiments, it also includes:

[0078] If the number of emergency scheduling times of the coroutine plus one is greater than the maximum value within the allowed range, the number of emergency scheduling times of the coroutine is set to the default value, and the coroutine is linked to the end of the coroutine queue; the coroutine queue is used to manage coroutines that are blocked during task execution and newly created coroutines.

[0079] If the number of emergency dispatches of a coroutine plus one is greater than the maximum value of the allowed range, the number of emergency dispatches of the coroutine is set to the default value (the default value is zero), and the emergency dispatch flag of the coroutine is cleared, and the coroutine will no longer be urgently dispatched. This can prevent one or some coroutines from being continuously urgently dispatched and affecting the execution of other tasks. For example. The maximum value in the allowed range is 3, which means that the coroutine is allowed to be urgently dispatched 3 times. If the number of emergency dispatches of a coroutine reaches 3 times, the number of emergency dispatches of the coroutine is set to the default value, and the emergency dispatch flag of the coroutine is cleared, and the coroutine will no longer be urgently dispatched.

[0080] In addition, if the number of emergency dispatches of the coroutine is greater than the maximum value within the allowed range after adding one, the coroutine will be linked to the end of the coroutine queue; the coroutine queue is used to manage coroutines that are blocked during task execution and newly created coroutines.

[0081] In some embodiments, it also includes:

[0082] Determine whether the coroutine queue array is empty;

[0083] If it is empty, select elements from the coroutine queue and add them to the coroutine queue array.

[0084] Wherein, in some embodiments, selecting an element from the coroutine queue and adding it to the coroutine queue array includes:

[0085] A target number of elements are selected from the head of the coroutine queue and added to the coroutine queue array; the target number is equal to the size of the coroutine queue array.

[0086] The coroutines corresponding to the elements in the coroutine queue array can be called earlier than the coroutines corresponding to the elements in the coroutine queue. When there is a vacancy in the coroutine queue array, select elements from the coroutine queue to add to the coroutine queue array. The order from the head to the tail of the coroutine queue is the order in which elements are selected from the coroutine queue. If N elements need to be selected from the coroutine queue to add to the coroutine queue array, select the first N elements from the head of the coroutine queue to add to the coroutine queue array.

[0087] If the coroutine queue array is empty, select elements from the coroutine queue to fill the coroutine queue array. For example, if the size of the coroutine queue array is 64, then when the coroutine queue array is empty, select the first 64 elements from the coroutine queue to fill the coroutine queue array. The elements in the coroutine queue are the coroutines that are blocked during the task execution and the elements corresponding to the newly created coroutines. The elements in the coroutine queue array are pointers to the coroutine description structure, and the elements in the coroutine queue are also pointers to the coroutine description structure.

[0088] In some embodiments, it also includes:

[0089] In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine is set with a high execution priority flag;

[0090] If the coroutine is set with a high execution priority flag, the coroutine is urgently scheduled.

[0091] In some embodiments, it also includes:

[0092] If the coroutine is not set with a high execution priority flag and the coroutine does not meet the emergency scheduling condition, the coroutine is linked to the end of the coroutine queue.

[0093] The high execution priority flag is a parameter specified when the coroutine is created. As shown in Table 1, the coroutine description structure can also include a high execution priority flag. The default value of the high execution priority field is 0. If the value of the high execution priority field is 1, it indicates that the coroutine has a high execution priority flag set. If the coroutine is set with a high execution priority flag, the coroutine is urgently scheduled. If the coroutine is not set with a high execution priority flag, but the coroutine is set with an emergency dispatch flag, the coroutine is also urgently dispatched. If the coroutine does not have a high execution priority flag and an emergency dispatch flag set, the coroutine is linked to the end of the coroutine queue.

[0094] For example, if the coroutine is blocked and the execution right is relinquished, if the coroutine is set with a high execution priority flag, first determine whether the value of the coroutine's emergency dispatch times plus 1 is greater than the maximum value in the allowed range. If it is not greater than the maximum value in the allowed range, then increase the coroutine's emergency dispatch times by 1, and insert the pointer of the coroutine description structure of the coroutine into the position 2^(6-N) in the coroutine queue array, where N is the emergency dispatch times. If it is greater than, retain the high execution priority flag of the coroutine, update the emergency dispatch times of the coroutine to the default value of 0, and link the coroutine to the end of the coroutine queue. If the coroutine is not set with a high execution priority flag but is set with an emergency dispatch flag, first determine whether the value of the coroutine's emergency dispatch times plus 1 is greater than the maximum value in the allowed range. If it is not greater than the maximum value in the allowed range, then increase the coroutine's emergency dispatch times by 1, and insert the pointer of the coroutine description structure of the coroutine into the position 2^(6-N) in the coroutine queue array, where N is the emergency dispatch times. If it is greater, the emergency dispatch flag of the coroutine is cleared, and the emergency dispatch times of the coroutine are updated to the default value 0, and the coroutine is linked to the end of the coroutine queue. If the coroutine has neither a high execution priority flag nor an emergency dispatch flag set, the coroutine is linked to the end of the coroutine queue.

[0095] In some embodiments, it also includes:

[0096] Create a new coroutine and link it to the end of the coroutine queue.

[0097] When a new coroutine is required for an executing coroutine, a new coroutine is created and linked to the end of the coroutine queue.

[0098] In some embodiments, it also includes:

[0099] In response to the coroutine relinquishing the execution right due to completion of the assigned task, the coroutine is destroyed.

[0100] The coroutine transfers the execution right and completes the assigned task, that is, the life cycle of the coroutine ends, and the coroutine is destroyed at this time.

[0101] The coroutine scheduling method provided by the present invention can be applied to a variety of scenarios. For example, when downloading multimedia content from the Internet or browsing online, network transmission congestion usually occurs due to network reasons. When the content download or online preview progress reaches more than 95%, the user often urgently hopes that the task will be completed at the fastest speed. In the face of this problem, the user can develop his own application system based on the coroutine scheduling method provided by the present invention, and add modules such as task management, task allocation, task progress display, log, statistics, and security. The application system divides the download task into specified sub-divisions and specifies the dependencies between the sub-divisions. The divided tasks are handed over to the newly created coroutine for processing, and the high execution priority identifier of the newly created coroutine can be specified; a mapping relationship table between tasks and coroutines is established. In the task instruction, the program is required to read the mapping relationship table between tasks and coroutines to fill in its own dependent and dependent attribute fields, and specify other download requirements. In the task instruction, the program is required to write the task completion degree into the task schedule table of the application system. The application system discloses the task progress through the interface of the task progress display module. A clear mark that a task has been completed is set in the application system. The application system can be used as an independent system or in the form of a plug-in. For example, a player plug-in, a browser plug-in, etc.

[0102] For another example, large-scale supply chain management systems often involve more than 100,000 raw materials, required accessories, etc., and also include logistics, finance and other associated processes. At present, when facing urgent tasks, the supply chain management system cannot dynamically and timely remind each link and each element of the task urgency, so the corresponding team cannot identify potential problems such as tight schedule and insufficient manpower. Shortening the construction period is a systematic project. Especially for large-scale supply chain management systems, the change of one link will bring about a large number of state changes in subsequent links. The use of the coroutine scheduling method provided by the present invention can solve this problem. Users can develop their own application systems based on the coroutine scheduling method provided by the present invention. The application system sets a global task schedule based on the existing process display, task segmentation, and task dependency. The tasks of the specific links are handed over to the newly created coroutine for processing, and the high execution priority identifier of the newly created coroutine can be specified; a mapping relationship table between tasks and coroutines is established. In the task instruction, the program is required to read the mapping relationship table between tasks and coroutines to fill in its own dependent and dependent attribute fields, and specify other business logic requirements of this link. In the task instruction, the program is required to write the task completion degree into the task schedule of the application system. The application system reads the task schedule and displays the task progress of each link in the existing supply chain management process. The application system sets a clear sign that a task has been completed to improve the clarity of the process. At the same time, the links with task completion exceeding 95% and the links with high execution priority are reminded in eye-catching colors, so that the team members of the link are alerted. The process management personnel can also adjust the subsequent work deployment.

[0103] In summary, the coroutine scheduling method provided by the present invention determines the actual execution requirements of a task based on the degree of completion of the task and / or whether other tasks that depend on the task are empty. The degree of completion of a task reaches a preset threshold and / or other tasks that depend on the task are not empty, which can reflect that the task actually has an emergency processing requirement. Therefore, when the degree of completion of a task reaches a preset threshold and / or other tasks that depend on the task are not empty, the coroutine responsible for the task is urgently scheduled, which can promptly and effectively respond to the actual emergency processing requirements of the task and speed up the completion of the task.

[0104] The present invention also provides a coroutine scheduling system, and the system described below can be referred to in correspondence with the method described above. The system includes:

[0105] A judgment unit, configured to judge whether the coroutine satisfies an emergency scheduling condition in response to the coroutine giving up the execution right due to task blocking; the emergency scheduling condition includes: other tasks dependent on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0106] The scheduling unit is used to urgently schedule the coroutine if the coroutine meets the emergency scheduling condition.

[0107] Based on the above embodiment, as a specific implementation mode, the scheduling unit includes:

[0108] A scheduling order determination subunit, used to determine the scheduling order of the coroutine according to the number of emergency scheduling of the coroutine; wherein, the more the number of emergency scheduling of the coroutine, the higher the scheduling order of the coroutine;

[0109] The coroutine scheduling subunit is used to schedule the coroutine according to the scheduling order.

[0110] Based on the above embodiment, as a specific implementation mode, the scheduling order determination subunit is specifically used for:

[0111] According to the number of emergency scheduling of the coroutine, the position of the identifier corresponding to the coroutine in the coroutine queue array is determined, and the identifier corresponding to the coroutine is inserted into the determined position to schedule the coroutine according to the position of the identifier corresponding to the coroutine in the coroutine queue array.

[0112] Based on the above embodiment, as a specific implementation mode, the scheduling order determination subunit is specifically used for:

[0113] According to the number of emergency dispatches of the coroutine, the position of the pointer of the coroutine description structure of the coroutine in the coroutine queue array is determined, and the pointer of the coroutine description structure of the coroutine is inserted into the determined position, wherein the coroutine description structure is used to describe the information and status of the coroutine.

[0114] Based on the above embodiment, as a specific implementation method, it also includes:

[0115] A second judgment unit is used to judge whether the number of emergency scheduling times of the coroutine plus one is greater than the maximum value within the allowed range;

[0116] The calculation unit is used to increase the emergency scheduling number of the coroutine by one if it is not greater than, and determine the position of the identifier corresponding to the coroutine in the coroutine queue array according to the emergency scheduling number after the increase.

[0117] Based on the above embodiment, as a specific implementation method, it also includes:

[0118] The first setting unit is used to set the emergency scheduling number of the coroutine to a default value if the emergency scheduling number of the coroutine plus one is greater than the maximum value within the allowed range, and link the coroutine to the end of the coroutine queue; the coroutine queue is used to manage coroutines that are blocked in the task execution process and newly created coroutines.

[0119] Based on the above embodiment, as a specific implementation method, it also includes:

[0120] The second setting unit is used to set an emergency scheduling flag for the coroutine if the coroutine meets the emergency scheduling condition.

[0121] Based on the above embodiment, as a specific implementation method, it also includes:

[0122] A third judging unit, used to judge whether the coroutine queue array is empty;

[0123] The adding unit is used to select elements from the coroutine queue and add them to the coroutine queue array if it is empty.

[0124] Based on the above embodiment, as a specific implementation mode, the adding unit is specifically used for:

[0125] A target number of elements are selected from the head of the coroutine queue and added to the coroutine queue array; the target number is equal to the size of the coroutine queue array.

[0126] Based on the above embodiment, as a specific implementation method, it also includes:

[0127] The creation unit is used to create a new coroutine and link the newly created coroutine to the end of the coroutine queue.

[0128] Based on the above embodiment, as a specific implementation method, it also includes:

[0129] The destroying unit is used to destroy the coroutine in response to the coroutine giving up the execution right due to completing the assigned task.

[0130] Based on the above embodiment, as a specific implementation method, it also includes:

[0131] A fourth judgment unit, configured to judge whether a high execution priority flag is set for the coroutine in response to the coroutine relinquishing execution rights due to task blocking;

[0132] The second scheduling unit is used to urgently schedule the coroutine if the coroutine is set with a high execution priority flag.

[0133] Based on the above embodiment, as a specific implementation method, it also includes:

[0134] The sorting unit is used to link the coroutine to the end of the coroutine queue if the coroutine is not set with a high execution priority flag and the coroutine does not meet the emergency scheduling condition.

[0135] The judgment unit is a functional unit in the coroutine queue sorting module. The coroutine queue sorting module is a module that is executed after the coroutine relinquishes the execution right. If the coroutine relinquishes the execution right due to task blocking, the coroutine queue sorting module performs re-sorting.

[0136] In a specific implementation, the coroutine queue sorting module performs the following operations:

[0137] The coroutine queue sorting module has an internal dedicated coroutine queue array. The array size is 64, and the array elements are pointers to the coroutine description structure. The function of the coroutine queue array is to place the coroutines that need to be urgently scheduled in the first 2^(6-N) scheduling positions so that the coroutine can get the execution right as soon as possible. (N represents the number of emergency dispatches next, and the value range is 1,2,3). That is, the coroutines that need to be urgently dispatched may be inserted into the 32nd, 16th, and 8th positions of the coroutine queue array. The coroutine can be urgently dispatched up to three times. The coroutine queue sorting module first determines whether the coroutine queue array is empty. If it is empty, select elements from the coroutine queue to fill the coroutine queue array. If it is not empty, all elements in the coroutine queue array are moved forward one position (the first element of the array has been taken away), and elements are taken from the head of the coroutine queue and filled into the tail of the coroutine queue array.

[0138] The destruction unit is a functional unit in the destruction module. If the coroutine that relinquishes the execution right has completed the assigned task (life cycle has ended), the destruction module is called to clean up the coroutine. If the coroutine relinquishes the execution right due to blocking, and the coroutine does not set the high execution priority flag and does not meet the conditions for setting the emergency dispatch flag, the coroutine is linked to the end of the coroutine queue. There are two conditions for setting the emergency dispatch flag for the coroutine: one is that the "who depends on" linked list of the coroutine is not empty; the other is that the task completion rate reaches 95% or above. If the coroutine is set with a high execution priority flag, it is determined whether the value of the coroutine's "Number of Emergency Dispatch" plus 1 is greater than 3. If it is not greater than 3 (that is, the value of "Number of Emergency Dispatch" is <= 3), the value of the "Number of Emergency Dispatch" field of the coroutine is updated (the value is added by 1), and the pointer corresponding to the coroutine is inserted into the position represented by 2^(6-N) in the coroutine queue array. N is the value of "Number of Emergency Dispatch". If it is greater than 3, the high execution priority flag of the coroutine is retained, its "Number of Emergency Dispatch" is updated to the default value of 0, and the coroutine is linked to the end of the coroutine queue. The coroutine queue is a circular singly linked list, which is used to manage the collection of coroutines in the system that have not been destroyed except for the coroutines in the coroutine queue array and the coroutines that have been scheduled, that is, including the coroutines that have blocked tasks during execution and newly created coroutines.

[0139] If the coroutine does not have a high execution priority flag set but meets the conditions for setting an emergency dispatch flag, then set the emergency dispatch flag of the coroutine (update the value to 1), and determine whether the value after adding 1 to the "Number of Emergency Dispatches" is greater than 3. If it is not greater than 3 (that is, the value of the "Number of Emergency Dispatches" is <= 3), then update the value of the "Number of Emergency Dispatches" field of the coroutine (add 1 to the value), and insert the pointer corresponding to the coroutine into the position represented by 2^(6-N) in the coroutine queue array. If it is greater than 3, update its "Number of Emergency Dispatches" to the default value 0, clear its emergency dispatch flag (update the value to 0), and link the coroutine to the end of the coroutine queue. When inserting a coroutine into the coroutine queue array, remove the elements at the end of the original array from the array, and link the removed elements to the head of the coroutine queue.

[0140] After the coroutine queue sorting module sets the first element of the array as the incoming coroutine, the coroutine switching management module in the coroutine scheduling system is called. The function of the coroutine switching management module is to save the context of the outgoing coroutine and restore the context of the incoming coroutine. The outgoing coroutine can be null, indicating that its context does not need to be saved. The outgoing coroutine is null only when the system starts.

[0141] When a coroutine is about to be blocked, the coroutine execution right transfer management module is scheduled to perform preparatory work before the coroutine hands over the execution right, such as updating the coroutine's own task completion degree, registering messages with the registration center, etc.

[0142] The message registration center and the coroutine queue are both system resources. The message registration center is shared across the system, and each module in the system can perform read and write operations, and there are no locks for reading and writing.

[0143] The creation unit is a functional unit in the coroutine creation module in the coroutine scheduling system. The coroutine creation module is the instruction code called when the executing coroutine has a new coroutine requirement. The coroutine creation module also provides an API for external programs to call. Calling the coroutine creation module will not block the coroutine. The coroutine destruction module is used to destroy the coroutine. Only the coroutine that has completed the task will be destroyed.

[0144] The present invention also provides a coroutine scheduling device, referring to Figure 3 As shown, the device includes a memory 1 and a processor 2 .

[0145] Memory 1, used for storing computer programs;

[0146] Processor 2 is used to execute the computer program to implement the following steps:

[0147] In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine meets an emergency scheduling condition; the emergency scheduling condition includes: other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0148] If the coroutine meets the emergency scheduling condition, the coroutine is urgently scheduled.

[0149] In some embodiments, the memory 1 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.

[0150] In addition, the memory 1 may include a read-only memory and a random access memory, and provides instructions and data to the processor 2. A portion of the memory 1 may also include an NVRAM. The memory 1 stores an operating system and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and processing hardware-based tasks.

[0151] The processor 2 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic device, a microprocessor or any conventional processor, etc. The processor 2 may call a program stored in the memory 1.

[0152] The communication interface is used to connect to other devices or systems.

[0153] For an introduction to the device provided by the present invention, please refer to the above method embodiment, and the present invention will not be elaborated here.

[0154] The present invention also provides a computer program product, comprising a computer program / instruction, wherein when the computer program / instruction is executed by a processor, the following steps are implemented:

[0155] In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine meets an emergency scheduling condition; the emergency scheduling condition includes: other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0156] If the coroutine meets the emergency scheduling condition, the coroutine is urgently scheduled.

[0157] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps can be implemented:

[0158] In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine meets an emergency scheduling condition; the emergency scheduling condition includes: other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold;

[0159] If the coroutine meets the emergency scheduling condition, the coroutine is urgently scheduled.

[0160] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0161] For an introduction to the computer-readable storage medium provided by the present invention, please refer to the above method embodiment, and the present invention will not elaborate on it here.

[0162] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the devices, equipment, and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0163] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0164] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0165] The above is a detailed introduction to the coroutine scheduling method, device, computer program product and medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A coroutine scheduling method, characterized in that: include: In response to the coroutine relinquishing execution rights due to task blocking, determining whether the coroutine meets an emergency scheduling condition; The emergency dispatch conditions include: other tasks that depend on the task that the coroutine is responsible for executing are not empty and / or the completion degree of the task that the coroutine is responsible for executing reaches a preset threshold; If the coroutine meets the emergency dispatch condition, the coroutine is urgently dispatched; The emergency dispatching process includes: Determine the scheduling order of the coroutine according to the number of emergency scheduling of the coroutine; wherein, within the allowed range, the more the number of emergency scheduling of the coroutine is, the higher the scheduling order of the coroutine is; Scheduling the coroutine according to the scheduling order; Determining the scheduling order of the coroutines according to the number of emergency scheduling of the coroutines includes: Determine the position of the identifier corresponding to the coroutine in the coroutine queue array according to the number of emergency scheduling of the coroutine, and insert the identifier corresponding to the coroutine at the determined position, so as to schedule the coroutine according to the position of the identifier corresponding to the coroutine in the coroutine queue array; Determining the position of the identifier corresponding to the coroutine in the coroutine queue array according to the number of emergency dispatches of the coroutine, and inserting the identifier corresponding to the coroutine into the determined position comprises: According to the number of emergency dispatches of the coroutine, the position of the pointer of the coroutine description structure of the coroutine in the coroutine queue array is determined, and the pointer of the coroutine description structure of the coroutine is inserted into the determined position; the coroutine description structure is used to describe the information and status of the coroutine.

2. The coroutine scheduling method according to claim 1, characterized in that: According to the number of emergency dispatches of the coroutine, before determining the position of the identifier corresponding to the coroutine in the coroutine queue array, the method further includes: Determine whether the number of emergency dispatches of the coroutine after adding one is greater than the maximum value within the allowed range; If not, the emergency dispatch times of the coroutine are increased by one, and the position of the identifier corresponding to the coroutine in the coroutine queue array is determined according to the increased emergency dispatch times.

3. The coroutine scheduling method according to claim 2, characterized in that: Also includes: If the number of emergency scheduling times of the coroutine plus one is greater than the maximum value within the allowed range, the number of emergency scheduling times of the coroutine is set to the default value, and the coroutine is linked to the end of the coroutine queue; the coroutine queue is used to manage coroutines that are blocked during task execution and newly created coroutines.

4. The coroutine scheduling method according to claim 1, characterized in that: Also includes: Determine whether the coroutine queue array is empty; If it is empty, select elements from the coroutine queue and add them to the coroutine queue array.

5. The coroutine scheduling method according to claim 4, characterized in that: Selecting an element from the coroutine queue and adding it to the coroutine queue array includes: A target number of elements are selected from the head of the coroutine queue and added to the coroutine queue array; the target number is equal to the size of the coroutine queue array.

6. The coroutine scheduling method according to claim 1, characterized in that: Also includes: If the coroutine meets the emergency dispatch condition, an emergency dispatch flag is set for the coroutine.

7. The coroutine scheduling method according to claim 1, characterized in that: Also includes: Create a new coroutine and link it to the end of the coroutine queue.

8. The coroutine scheduling method according to claim 1, characterized in that: Also includes: In response to the coroutine relinquishing the execution right due to completion of the assigned task, the coroutine is destroyed.

9. The coroutine scheduling method according to any one of claims 1 to 8, characterized in that: Also includes: In response to the coroutine giving up the execution right due to task blocking, determining whether the coroutine is set with a high execution priority flag; If the coroutine is set with a high execution priority flag, the coroutine is urgently scheduled.

10. The coroutine scheduling method according to claim 9, characterized in that: Also includes: If the coroutine is not set with a high execution priority flag and the coroutine does not meet the emergency scheduling condition, the coroutine is linked to the end of the coroutine queue.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the coroutine scheduling method as described in any one of claims 1 to 10 are implemented.

12. A coroutine scheduling device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the coroutine scheduling method as described in any one of claims 1 to 10 when executing the computer program.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the coroutine scheduling method according to any one of claims 1 to 10 are implemented.

Citation Information

Patent Citations

  • Asynchronous task execution method, device and system

    CN106980546A