Task execution method and device, electronic equipment and storage medium
By pre-generating an object pool and automatically returning the object, the performance bottlenecks and memory fragmentation problems caused by frequent memory allocation and release in high-concurrency environments are solved, efficient object management and memory utilization are achieved, and system performance and stability are improved. .
Patent Information
- Application Number
- CN202411289076.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-06
AI Technical Summary
In high-performance computing and multi-threaded applications, frequent memory allocation and release operations lead to performance bottlenecks and memory fragmentation problems, especially in high-concurrency environments, where system performance is significantly reduced.
Provide a task execution method, which pre-creates an object pool and automatically returns the object to the object pool after the object is used for reuse, avoiding frequent memory allocation and release operations, and using object pointers to obtain and return objects from the object pool. , reduce the overhead of construction and destruction.
Effectively manage the life cycle of objects, reduce memory fragmentation, improve memory utilization, improve system response speed and performance, and improve stability and flexibility in high concurrency environments.
Smart Images

Figure CN119088531A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to the field of data processing. More specifically, the present disclosure provides a task execution method, device, electronic device, storage medium, and computer program product. Background Art
[0002] Threads in a process need to use objects when performing tasks. When a new object is needed, a predetermined memory allocation operator can be used to allocate memory first and call the constructor to construct the object. When the object is no longer needed, a predetermined memory release operator can be used to call the destructor to destroy the object and release the memory.
[0003] In high-performance computing and multi-threaded applications, frequent memory allocation and release operations can lead to serious performance bottlenecks and memory fragmentation problems. Each allocation and release of memory requires complex management operations, which can significantly increase system overhead and degrade system performance in a high-concurrency environment. Summary of the invention
[0004] The present disclosure provides a task execution method, device, electronic device, storage medium and computer program product.
[0005] According to one aspect of the present disclosure, a task execution method is provided, comprising: in response to determining that a target thread in a process is to execute a target task, determining and removing a target node corresponding to the target thread from a node set, wherein the node set includes a plurality of object nodes, each object node includes an object pointer, and the object pointer points to an address of an object corresponding to the object node in a predetermined storage space; using the object pointer of the target node to obtain a target object from an object pool corresponding to the node set, and executing the target task based on the target object; and in response to determining that the target task has been completed, inserting the target node into the node set.
[0006] According to another aspect of the present disclosure, a task execution device is provided, including a removal module, an execution module and an insertion module. The removal module is used to determine and remove the target node corresponding to the target thread from the node set in response to determining that the target thread in the process is to execute the target task, wherein the node set includes a plurality of object nodes, each object node includes an object pointer, and the object pointer points to the address of the object corresponding to the object node in a predetermined storage space. The execution module is used to obtain the target object from the object pool corresponding to the node set using the object pointer of the target node, and execute the target task based on the target object. The insertion module is used to insert the target node into the node set in response to determining that the target task has been completed.
[0007] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method provided by the present disclosure.
[0008] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the method provided by the present disclosure.
[0009] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method provided by the present disclosure is implemented.
[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0012] Figure 1 is a schematic flow chart of a task execution method according to an embodiment of the present disclosure;
[0013] Figure 2 is a schematic diagram of a task execution method according to another embodiment of the present disclosure;
[0014] Figure 3 is a schematic flow chart of a task execution method according to another embodiment of the present disclosure;
[0015] Figure 4A is a schematic diagram of a node set scene before a target node is moved out according to an embodiment of the present disclosure;
[0016] Figure 4B It is a schematic diagram of a node set scene after a target node is moved out according to an embodiment of the present disclosure.
[0017] Figure 5 is a schematic diagram of removing a target node from a multiple node set scenario according to an embodiment of the present disclosure;
[0018] Figure 6 is a schematic diagram of inserting a target node into a node set scene according to an embodiment of the present disclosure;
[0019] Figure 7 It is a schematic diagram of inserting a target node into a scene when multiple nodes are assembled according to an embodiment of the present disclosure;
[0020] Figure 8 is a schematic structural block diagram of a task execution device according to an embodiment of the present disclosure; and
[0021] Fig. 9 It is a structural block diagram of an electronic device used to implement the task execution method of an embodiment of the present disclosure. DETAILED DESCRIPTION
[0022] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0023] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0024] In the technical solution of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0025] In one technical solution, when a new object is needed, a predetermined memory allocation operator is used to allocate memory first and call a constructor to construct the object. When the object is no longer needed, a predetermined memory release operator can be used to call a destructor to destroy the object and release memory.
[0026] However, the above technical solution works well in a single-threaded environment, but in a high-concurrency environment, it is easy to cause memory fragmentation problems because memory needs to be frequently allocated and released during the use of objects. In addition, when the object is large, it will also bring additional construction and destruction performance losses. In a multi-threaded environment, a synchronization mechanism is needed to ensure thread safety, which further reduces program performance.
[0027] The disclosed embodiment aims to provide a task execution method, which can pre-generate an object pool containing multiple objects. When an object is needed, a target node can be obtained from a node set, and then an object pointer can be obtained from the target node, and then the target object can be obtained from the object pool through the object pointer to execute the target task. When the target object is used, the target node can be inserted into the node set, and the target object can be automatically returned to the object pool.
[0028] It can be seen that the technical solution provided by the present disclosure avoids frequent memory allocation and release operations by pre-allocating a certain number of objects and automatically returning the objects to the object pool for reuse after use. It can also effectively manage the life cycle of objects, reduce memory fragmentation, and improve memory utilization. In addition, since objects can be quickly allocated and released without the need to reconstruct and destroy objects, the overhead required for construction and destruction is reduced, so the response speed, performance and stability can be improved in a high-concurrency environment. In addition, it can also adapt to the object management needs of different types and life cycles, and can be adjusted and optimized according to specific application scenarios, with strong flexibility and scalability.
[0029] The technical solution provided by the present disclosure will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0030] Figure 1 is a schematic flowchart of a task execution method according to an embodiment of the present disclosure.
[0031] As shown in the figure, the task execution 100 may include operations S110 to S130.
[0032] In operation S110, in response to determining that a target thread in a process is to execute a target task, a target node corresponding to the target thread is determined and removed from a node set, wherein the node set includes a plurality of object nodes, each object node includes an object pointer, and the object pointer points to an address of an object corresponding to the object node in a predetermined storage space.
[0033] For example, a process includes multiple threads, the execution order between the multiple threads includes at least one of serial and parallel, and the target thread is a thread that needs to be executed at the current moment in the process.
[0034] For example, a process corresponds to an object pool, which includes multiple objects. The object pool can use a list, a queue, or a stack to store these objects. The objects in the object pool can include data to be read or written, and accordingly, the target task can be to perform a read operation or a write operation on the data to be read or written. The objects in the object pool can also include data processing logic, which is, for example, a method or function for processing data, and accordingly, the target task includes calling the data processing logic to process the relevant data. The objects in the object pool can be the same, for example, the object pool includes 5 objects, and the 5 objects are the same function.
[0035] For example, a process corresponds to at least one node set, each node set includes at least one object node, and for an object pool and at least one node set corresponding to the same process, the object nodes in all node sets correspond one-to-one to the objects in the object pool. For example, if the object pool includes 12 objects, then each node set includes 12 object nodes in total.
[0036] In the process of determining the target node from the node set, for example, an object node can be randomly selected from the node set as the target node. For another example, the object nodes in the node set can be arranged in the form of a linked list, a queue, etc., and the target node can be selected from the node set according to the order of the object nodes. After determining the target node, it is also necessary to remove the target node from the node set, so as to avoid other threads using the target object corresponding to the target node during the process of the target thread using the target object.
[0037] In operation S120, a target object is acquired from an object pool corresponding to the node set using an object pointer of the target node, and a target task is executed based on the target object.
[0038] For example, the object node includes an object pointer, which points to the address of the object corresponding to the object node in a predetermined storage space, and the predetermined storage space can be a memory. It can be seen that through the object node, the object pointer can be found, and then the target object can be obtained from the predetermined storage space through the address pointed to by the object pointer, and then the target task can be executed.
[0039] In operation S130 , in response to determining that the target task has been completed, a target node is inserted into the node set.
[0040] It should be noted that the data elements included in the object node can be stored in a predetermined storage space. Removing an object node (such as a target node) from a node set means that the node set no longer includes the object node, but the data elements included in the object node may not be deleted from the predetermined storage space, so that the object node continues to be stored in the predetermined storage space.
[0041] When the target task is completed, the object node can be inserted into the node set, so that when other threads need to execute tasks later, the object can be reused based on the reinserted object node, for example, the reinserted object node can be used as the target node, and the target object corresponding to the object node can be used again to execute the task.
[0042] The technical solution provided by the present disclosure avoids frequent memory allocation and release operations by pre-allocating a certain number of objects and automatically returning the objects to the object pool for reuse after use. It can also effectively manage the life cycle of objects, reduce memory fragmentation, and improve memory utilization. In addition, since objects can be quickly allocated and released without the need to reconstruct and destroy objects, the overhead required for construction and destruction is reduced, so the response speed, performance and stability can be improved in a high-concurrency environment. In addition, it can also adapt to the object management needs of different types and life cycles, and can be adjusted and optimized according to specific application scenarios, with strong flexibility and scalability.
[0043] Figure 2is a schematic diagram of a task execution method according to another embodiment of the present disclosure.
[0044] like Figure 2 As shown, in this embodiment, the object pool Pool and the node set can be created in response to the process startup. For example, in response to the process startup, the object initialization can be performed according to the acquired initialization parameters to obtain the object pool Pool corresponding to the process. Then, the node set can be determined according to the object pool Pool.
[0045] When the process starts, you can get the initialization parameters, which may include the symmetric pool capacity, the number of node sets, the number of object nodes of each node set, etc. After getting the initialization parameters, you can first verify whether the initialization parameters are legal, and then if they are legal, allocate some space in the memory, create object nodes of the specified capacity, and allocate the object nodes contained in each node set according to the number of node sets. In addition, if the object includes data, you can also call the cleanup function to reset the state of each object.
[0046] During the process running, the tasks of each thread in the process can be executed. For example, in response to determining that the target thread Thread in the process is to execute the target task, the target node corresponding to the target thread Thread is determined and removed from the node set. Then, the target object object is obtained from the object pool Pool corresponding to the node set using the object pointer of the target node, and the target task is executed based on the target object object. Then, in response to determining that the target task has been completed, the target node is inserted into the node set, and the target object object is returned to the object pool Pool. In addition, the target object object can also be reset for reuse next time.
[0047] After the process ends, the objects in the object pool Pool can be destroyed by calling the destructor and the memory Mermory can be released, thereby preventing the objects from occupying the space of the memory Mermory.
[0048] It can be seen that in this embodiment, the objects in the object pool Pool are created when the process starts and destroyed when the process ends. During the process running, there is no need to destroy the objects in the object pool Pool, so that objects can be directly obtained from the object pool Pool when needed, and returned to the object pool Pool when not needed, without repeatedly constructing and destroying objects.
[0049] It should be noted that after the object pool is initialized, the number of objects and the number of node sets in the object pool can remain unchanged. In practical applications, the number of objects and the number of node sets can be changed by configuring initialization parameters according to actual needs. For example, by increasing the number of node sets to adapt to a larger concurrency, performance and stability can be improved.
[0050] Figure 3 is a schematic flowchart of a task execution method according to another embodiment of the present disclosure.
[0051] In this embodiment, the task execution method 300 may include operations S301 to S304 and operation S310.
[0052] In operation S301 , in response to a process being started, an object pool and a node set are created.
[0053] In operation S302, in response to determining that the target thread in the process is to execute the target task, it is determined whether the node set is an empty set.
[0054] If the target thread is to execute the target task and the node set is an empty set, operation S303 may be performed. If the target thread is to execute the target task and the node set is not an empty set, operation S310 may be triggered.
[0055] In operation S303, a target object is generated based on a predetermined method, and a target task is performed based on the generated target object. For example, the generation mode may include batch generation and single object generation.
[0056] In operation S304 , in response to determining that the target task has been completed and the target object is generated based on a predetermined manner, the target object is destroyed.
[0057] In operation S310, a target node corresponding to a target thread is determined and removed from a node set.
[0058] In the present embodiment, when an object is needed, an attempt can be made to obtain an object node from a node set first. If the object node is successfully obtained, the target object is searched through the object node, and the target task is then executed. If the object node is not successfully obtained, a new target object can be created to execute the target task. During the creation process, memory can be allocated first, and then a constructor can be called to construct a new target object. When the target object exceeds the object life cycle or the object cleanup function is called, it indicates that the target object has been used up. For the target object that has been used up, if the target object comes from an object pool, the target object can be returned to the object pool and the object node can be inserted into the node set. If the target object is generated based on a predetermined method, the target object can be destroyed, for example, a destructor is called to destroy the target object and release memory.
[0059] It should be noted that, in some embodiments, an object can be taken out from the object pool when an object is needed. If there is no available object in the object pool, it is necessary to wait or return an error. This object pool has a fixed capacity and a simple object allocation strategy, and cannot be dynamically expanded or shrunk to cope with dynamically changing object quantity requirements, which may lead to insufficient resources or waste of resources at certain times. Different from the above scheme, this embodiment can achieve dynamic expansion capability by dynamically generating new objects. Even if the number of objects initially allocated in the object pool is static, when there are no remaining objects in the object pool, new objects can be created to meet the demand. In this way, the number of objects can be dynamically expanded or shrunk to cope with dynamically changing object requirements and avoid insufficient resources or waste of resources caused by the expansion of object requirements in abnormal scenarios.
[0060] Figure 4A is a schematic diagram of a node set scene before a target node is moved out according to an embodiment of the present disclosure. Figure 4B It is a schematic diagram of a node set scene after a target node is moved out according to an embodiment of the present disclosure.
[0061] This embodiment takes a process corresponding to a node set as an example to illustrate the process of removing a target node from the node set.
[0062] like Figure 4A In this embodiment, the process includes thread 1, thread 2 and thread 3, and the three threads all correspond to the node set Set1. The node set Set1 includes a head node Node_H and at least one object node Node_1, Node_2, Node_3, and the head node Node_H and the object nodes Node_1, Node_2, Node_3 form a linked list structure. The head node Node_H includes calibration information. The object nodes Node_1, Node_2, and Node_3 may include data elements of the same type. Taking the object node Node_1 as an example, the object node Node_1 may include an object pointer and reference information, may also include other pointers to point to the next object node, and may also include a set identifier of the node set in which it is located.
[0063] The object nodes in the node set are arranged in order, and the calibration information of the head node Node_H is the same as the reference information of the object node at the target position in the arrangement order in the node set. The object node at the target position can be an object node adjacent to the head node Node_H, for example, the calibration information of the head node Node_H is the same as the reference information of the object node Node_1.
[0064] This embodiment uses the CAS (Compare And Swap) algorithm to determine the target node. The CAS algorithm contains three basic operands: variable V (variable V in this embodiment refers to calibration information), expected value E, and new value N. The CAS algorithm compares whether variable V and expected value E are the same. If they are the same, it means that variable V has not been modified, and the new value N is used to modify variable V. If they are different, it means that variable V has been updated by other threads. At this time, the expected value E is updated to the latest V value and re-executed.
[0065] In the process of determining and removing the target node, the current time may be taken as the first time T1, and the calibration information read at the first time T1 may be determined as the first expected value E1. It can be seen that the first expected value E1 is the same as the reference information of the target node Node_1.
[0066] Next, it can be determined whether the first expected value E1 is the same as the predetermined value, and the predetermined value can be Null. If the first expected value E1 is the same as the predetermined value, it means that the node set Set1 is an empty set. Since there are no remaining object nodes in the node set Set1, it is possible to wait and perform subsequent processing after the object nodes exist in the object pool. It is also possible to generate a new target object based on a predetermined method. If the first expected value E1 is different from the predetermined value, it means that the node set Set1 is not an empty set, and there are remaining object nodes in the node set Set1. At this time, the following operation of determining candidate nodes can be triggered.
[0067] Next, the candidate nodes can be determined based on the head node Node_H. For example, the object node adjacent to the head node Node_H is determined as the candidate node. In the actual processing process, the reference information can include, for example, the node address of the object node, so that the node address of the candidate node can be determined through the calibration information of the head node Node_H, and then the candidate node is obtained through the node address. It can be seen that in this example, the object node Node_1 is used as the candidate node.
[0068] Next, the reference information of the next object node of the candidate node in the linked list structure is determined as the first new value N1. That is, the reference information of the object node Node_2 located after the object node Node_1 is determined as the first new value N1.
[0069] Next, the current moment can be used as the second moment T2 to determine whether the calibration information (ie, variable V1) read at the second moment is consistent with the first expected value E1. For example, the compare_exchange_weak function is used to compare whether the first expected value E1 is the same as the calibration information (ie, variable V1) of the head node Node_H at this time.
[0070] If the first expected value E1 is the same as the variable V1, it means that between the first time T1 and the second time T2, the object node Node_1 is not removed from the node set Set1 due to the execution of tasks of other threads, and other object nodes are not inserted between the object node Node_1 and the head node Node_H.
[0071] Therefore, if Figure 4B As shown, the object node Node_1 can be determined as the target node and removed. It can be understood that the removal of the object node Node_1 will cause the change of the elements in the linked list structure, so the calibration information of the head node Node_H must be updated with the first new value N1. After the update, the calibration information in the head node Node_H is the same as the reference information of the object node Node_2, so that the object node Node_2 is adjacent to the head node Node_H. In addition, removing the object node Node_1 from the node set Set1 can also update the reference information of the object node Node_1, for example, the reference information includes a version number and a node address, which can increase the value of the version number by one.
[0072] If the first expected value E1 is different from the variable V1, it means that between the first moment T1 and the second moment T2, the object node Node_1 is removed from the node set Set1 due to the execution of tasks of other threads, or other object nodes are inserted between the first object node and the head node Node_H. Both of the above situations result in changes in the object nodes adjacent to the head node Node_H. Therefore, the first expected value E1 can be updated using the latest calibration information. For example, the calibration information read at the second moment can be updated to the first expected value E1, or the calibration information of the head node Node_H can be re-read and used as the updated first expected value E1. In addition, the candidate node can be re-determined. For example, after updating the first expected value E1, the above operation of determining whether the first expected value E1 is the same as the predetermined value can be re-executed to re-determine the target node.
[0073] It can be understood that the purpose of determining whether the first expected value E1 is consistent with the variable V1 in this embodiment is to determine whether the object node adjacent to the head node Node_H is changed due to the execution of tasks of other threads between the first moment T1 and the second moment T2. For example, the reference information includes a version number and a node address. If other threads update the object node adjacent to the head node Node_H, the node address will change; if other threads remove the object node adjacent to the head node Node_H and then reinsert it, at this time, although the node address does not change, the version number will change. Therefore, by comparison, it can be determined whether the object node adjacent to the head node Node_H is moved.
[0074] This embodiment uses the CAS algorithm to determine and remove the target node. The CAS algorithm is a lock-free algorithm that can reduce performance degradation caused by lock contention between threads, thereby improving concurrent processing capabilities and response speed.
[0075] The above embodiment takes a process corresponding to a node set as an example to illustrate the process of removing the target node from the node set. It should be noted that this embodiment takes the target position as the position adjacent to the head node as an example for illustration. In other embodiments, the target position can be other pre-set positions, which is not limited in this embodiment.
[0076] Figure 5 It is a schematic diagram of removing a target node from a multiple node set scenario according to an embodiment of the present disclosure.
[0077] like Figure 5 As shown, this embodiment takes a process corresponding to multiple node sets as an example to illustrate the process of removing a target node from a node set.
[0078] like Figure 5 As shown, in this embodiment, the process includes thread 1, thread 2 and thread 3, and the multiple node sets include node set Set1, node set Set2 and node set Set3. It can be seen that the difference between this embodiment and the previous embodiment is that the number of node sets is different. However, the structure of a single node set can refer to the previous embodiment. For example, each node set includes a head node and at least one object node, and the head node and the object node in the same node set form a linked list structure. The head node includes calibration information, and the calibration information in the head node is the same as the reference information of an object node adjacent to the head node. Taking node set Set1 as an example, node set Set1 includes a head node Node_H and at least one object node Node_1, Node_2, Node_3, and the head node Node_H and the object nodes Node_1, Node_2, Node_3 form a linked list structure. The head node Node_H includes calibration information, and the calibration information of the head node Node_H is the same as the reference information of the object node Node_1.
[0079] When there are multiple node sets Set1, Set2, and Set3, the first target node set can be determined from the multiple node sets Set1, Set2, and Set3 according to the order of the multiple node sets. For example, based on a self-incrementing atomic variable, the self-incrementing atomic variable can be modulo the total number of node sets, and the first target node set can be determined according to the modulo result. In this way, the thread tasks to be executed can be allocated to each node set according to the order of the node sets, for example, the node set Set1 is determined as the first target node set for the first time, and the node set Set2 is determined as the first target node set for the second time, thereby avoiding multiple threads from competing for the object nodes in the same node set, thereby improving load balancing.
[0080] After obtaining the first target node set, the target node can be determined from the first target node set. The process can refer to the previous embodiment, and this embodiment will not be described in detail. For example, taking the first target node set as the node set Set1 as an example, at this time, for the node set Set1, the calibration information of the head node Node_H read at the first moment T1 can be first determined as the first expected value E1, and then the candidate node is determined according to the head node Node_H, where the candidate node is the object node Node_1. Next, the reference information of the next object node of the candidate node in the linked list structure is determined as the first new value N1, where the first new value N1 is the reference information of the object node Node_2. Then, it is determined whether the calibration information of the head node Node_H read at the second moment is consistent with the first expected value E1, and different update strategies are selected according to whether they are consistent.
[0081] The above embodiment takes a process corresponding to multiple node sets as an example to illustrate the process of removing the target node from the node set. In addition, it should be noted that: Figure 5 The example in which the number of object nodes included in each node set is equal is used for illustration. In other embodiments, the number of object nodes included in each node set may be different.
[0082] Figure 6 It is a schematic diagram of inserting a target node into a node set scene according to an embodiment of the present disclosure.
[0083] This embodiment takes a process corresponding to a node set as an example to illustrate the process of inserting a target node into the node set.
[0084] like Figure 6In this embodiment, the process includes thread 1, thread 2 and thread 3, and the three processes all correspond to the node set Set1. The node set Set1 includes a head node Node_H and at least one object node Node_2, Node_3, and the head node Node_H and the object nodes Node_2, Node_3 form a linked list structure. The head node Node_H includes calibration information, and the object nodes Node_2 and Node_3 may include data elements of the same type. Taking the object node Node_2 as an example, the object node Node_2 may include reference information, and the object node Node_2 may also include the set identifier of the node set Set1 in which it is located. In addition, the object node Node_2 also needs to include other pointers to point to the next object node.
[0085] The calibration information of the head node Node_H is the same as the reference information of the object node at the target position in the node set. The object node at the target position can be an object node adjacent to the head node Node_H. For example, the calibration information of the head node Node_H is the same as the reference information of the object node Node_2.
[0086] This embodiment adopts the CAS algorithm to determine the target node. The CAS algorithm includes three basic operands: a variable V (in this embodiment, the variable V refers to calibration information), an expected value E, and a new value N.
[0087] The current time may be taken as the third time T3, and the calibration information of the head node Node_H read at the third time T3 may be determined as the second expected value E2. It can be seen that the second expected value E2 is the same as the reference information of the object node Node_2.
[0088] Next, the reference information of the target node is determined as the second new value N2. In this embodiment, the target node to be inserted is the object node Node_1, so this example uses the reference information of the object node Node_1 as the second new value N2.
[0089] Next, the current time may be taken as the fourth time T4 to determine whether the calibration information (ie, the variable V2) of the head node Node_H at the fourth time T4 is consistent with the second expected value E2.
[0090] If the second expected value E2 is the same as the variable V2, it means that between the third time T3 and the fourth time T4, the object node Node_2 adjacent to the head node Node_H is not removed, and no other object node is inserted between the head node Node_H and the adjacent object node Node_2. At this time, the calibration information is updated using the second new value N2, that is, the calibration information in the head node Node_H after the update is the same as the reference information of the object node Node_1, so that the object node Node_1 is adjacent to the head node Node_H, and the object node Node_1 points to the object node Node_2 originally adjacent to the head node Node_H, so that the object node Node_1 is inserted between the head node Node_H and the object node Node_2. In addition, inserting the object node Node_1 in the node set Set1 can also update the reference information of the object node Node_1, for example, the reference information includes a version number and a node address, which can increase the value of the version number by one.
[0091] If the second expected value E2 is different from the variable V2, it means that between the third time T3 and the fourth time T4, the object node Node_2 adjacent to the head node Node_H is removed, or another object node is inserted between the head node Node_H and the adjacent object node Node_2. Both of the above situations result in changes in the object nodes adjacent to the head node Node_H. Therefore, the second expected value E2 can be updated using the latest calibration information, and then it is re-determined whether the calibration information is consistent with the second expected value E2.
[0092] This embodiment adopts the CAS algorithm to insert the target node. The CAS algorithm is a lock-free algorithm that can reduce the performance degradation caused by lock competition between threads, thereby improving concurrent processing capabilities and response speed.
[0093] The above embodiment takes a process corresponding to a node set as an example to illustrate the process of inserting a target node into the node set.
[0094] Figure 7 It is a schematic diagram of inserting a target node into a scene when multiple nodes are gathered according to an embodiment of the present disclosure.
[0095] like Figure 7 As shown, this embodiment takes a process corresponding to multiple node sets as an example to illustrate the process of inserting a target node into a node set.
[0096] like Figure 7As shown, in this embodiment, the process includes thread 1, thread 2 and thread 3, and the multiple node sets include node set Set1, node set Set2 and node set Set3. The difference between this embodiment and the previous embodiment is that the number of node sets is different. However, the structure of a single node set can refer to the previous embodiment.
[0097] For example, each node set includes a head node and at least one object node, and the head node and the object nodes in the same node set form a linked list structure. The head node includes calibration information, and the calibration information in the head node is the same as the reference information of an object node adjacent to the head node. Taking the node set Set1 as an example, the node set Set1 includes a head node Node_H and at least one object node Node_2 and Node_3, and the head node Node_H and the object nodes Node_2 and Node_3 form a linked list structure. The head node Node_H includes calibration information, and the calibration information of the head node Node_H is the same as the reference information of the object node Node_2.
[0098] In this embodiment, the target node to be inserted is the object node Node_1. When there are multiple node sets Set1, Set2, and Set3, the second target node set can be determined from multiple node sets Set1, Set2, and Set3 according to the set identifier of the node set where the object node Node_1 is located. It can be seen that the second target node set in this embodiment is the node set Set1. Then the object node Node_1 is inserted into the second target node set. The insertion process can refer to the previous embodiment, and this embodiment will not be described in detail. For example, for the node set Set1, the second expected value E2 and the second new value N2 at the third moment T3 can be determined first, and then the second expected value E2 at the third moment T3 is compared with the calibration information (i.e., variable V2) at the fourth moment T4 to see if they are consistent, and different update strategies are selected according to whether they are consistent.
[0099] In this embodiment, there are multiple node sets Set1, Set2, and Set3. After multiple threads complete their tasks, they can return the object nodes to the corresponding node sets, avoiding multiple threads returning the object nodes at the same time, causing frequent updates of the calibration information in the head node, thereby improving load balancing.
[0100] The above embodiment takes a process corresponding to multiple node sets as an example to illustrate the process of inserting a target node into a node set. In addition, it should be noted that: Figure 7 The example in which the number of object nodes included in each node set is equal is used for illustration. In other embodiments, the number of object nodes included in each node set may be different.
[0101] It is understandable that the removal and insertion of object nodes will change the order of nodes in the linked list structure. For example, the order of a linked list structure is: node 0, node 1, node 2, node 3, node 4. After the removal and insertion of object nodes, the order of the new linked list structure is: node 5, node 1, node 2, node 3, node 4.
[0102] According to another embodiment of the present disclosure, the reference information includes a version number and a node address, the version number is determined based on the number of times the object node is moved, the movement includes removal and insertion, and the node address is used to represent the address of the object node in a predetermined storage space.
[0103] In one example, the value of the version number may be increased by 1 when the object node is removed from the node set, and the value of the version number may also be increased by 1 when the object node is inserted into the node set. In another example, for the two processes of the object node being removed from the node set and the object node being inserted into the node set, the value of the version number is increased by 1 only when one of the processes occurs, and the version number is not adjusted for the other process.
[0104] In some embodiments, a CAS algorithm may be used to manage object nodes in a node set. The CAS algorithm includes three basic operands: a variable V, an expected value E, and a new value N, wherein the variable V refers to calibration information.
[0105] If the reference information does not contain the version number but only the node address, since the calibration information is the same as the reference information of the object node at the target position, the calibration information also does not contain the version number, which will cause the CAS algorithm to have an ABA problem. The ABA problem refers to the following situation: Thread P1 reads the value of variable V as v1 at time t1 and sets E=v1. At time t2, P1 is preempted, thread P2 executes and updates variable V from v1 to v2, and then updates it to v1 again. At time t3, process P1 executes, thread P1 compares and finds that variable V is the same as the expected value E, so thread P1 sets variable V to the new value N. It can be seen that variable V is modified twice by thread P2, but thread P1 will mistakenly determine that variable V has not changed.
[0106] In this embodiment, the reference information includes a version number and a node address. When a thread updates a variable V, the value of the version number may be increased by one. For example, the current V value is 0x000e0011, and the V value obtained by thread P1 is 0x000e0011. If P1 is preempted and P2 changes the V value, the new version number is 0x00100011. Subsequently, thread P1 continues to execute. In the process of comparing whether the updated variable V is consistent with the expected value E, the version number and the node address in the reference information are compared. In this way, it can be found that the variable V has changed, thereby alleviating the ABA problem.
[0107] The above describes the role of the reference information including the version number. Next, the node address in the reference information is described.
[0108] In one example, the node address is the system address of the object node in the predetermined storage space. For example, if there are 100 objects stored at addresses 1000000-1000099, the node addresses in the reference information are 1000000-1000099.
[0109] In another example, the node address is an offset, wherein the address of the object node in the predetermined storage space is determined based on the offset and the base address. For example, if there are 100 objects stored at addresses 1000000 to 1000099, and the base address is 1000000, the node address in the reference information may be 00 to 99.
[0110] For example, taking the V value as 64 bits, some technical solutions will use a 16-bit version number and a 48-bit system address to represent the variable. The reason for using this method is that the system address does not start from 0. For example, the above address 1000000~1000099, although the last 00~99 can represent the address, the numbers before 00~99 also need to be represented, which causes the node address to occupy more bits, leaving fewer bits for the version number.
[0111] However, the short version number has the following disadvantages: after other threads preempt and modify the same object multiple times, the version number may be restored to its original state, which still cannot overcome the ABA problem. Taking the 3-digit version number as an example, the version number is 000 when it is not modified. After multiple modifications, the version number can be updated to 001, 010, 011, 100, 101, 110, 111, 000 in sequence. It can be seen that the version number of the object after the 8th modification is the same as the version number when the object is not updated, thus causing the ABA problem. Similarly, if the version number is 16 digits, it will be modified 65536 times (2 16 With current computer performance, it is relatively easy to update the same object 65536 times in a short period of time.
[0112] In this embodiment, since the node address is an offset with fewer bits, rather than a system address with more bits, a small number of bits can represent a large number of system addresses, thereby reducing the number of bits occupied by the node address. In the case of a limited total number of bits, more bits can be used to represent the version number, thereby reducing the possibility of restoring the original version of the version number of the object after multiple modifications, further alleviating the ABA problem. It can be seen that compared with the solution where the node address is the system address, the node address as an offset can further reduce the probability of the ABA problem.
[0113] In one example, the reference information is 64-bit data, and the number of bits of the version number can be flexibly selected according to actual needs, for example, the number of bits of the version number is 20 bits, 32 bits, 44 bits, 48 bits, etc., and the remaining bits can be used to represent the node address.
[0114] It should be noted that removing and inserting a node from a node set will change the nodes contained in the node set, but will not change the node address of the node. For example, the first object node is stored at address 1 in the predetermined storage space, where address 1 refers to the address calculated by the offset and the base address, and the second object node is stored at address 2 in the predetermined storage space. When the first object node is removed from the node set, the first object node no longer exists in the node set, but the first object node is still stored at address 1 in the predetermined storage space.
[0115] It should be noted that in the related art, the objects in the object pool lack an automated object lifecycle management mechanism. After the object is used, the user needs to manually return the object to the object pool, which can easily lead to memory leaks due to forgetting or incorrectly managing the object.
[0116] In this embodiment, after obtaining the target object, the life cycle of the object can be managed by the wrapper class. For example, after generating the target object or obtaining the target object from the object pool, the target object can be encapsulated into a wrapper object. The wrapper class is designed to not support copy operations, but only support move operations to ensure the uniqueness and security of the object. When constructing the wrapper object, it will record whether the object corresponds to an object node. Through the recorded information, it can be determined whether the object comes from the object pool or is generated based on a predetermined method, so that when the life cycle of the wrapper object ends, the object from the object pool can be automatically returned to the object pool, and the object generated based on the predetermined method can be automatically destroyed, thereby achieving efficient resource management and avoiding memory leaks and resource waste.
[0117] Figure 8 It is a schematic structural block diagram of a task execution device according to an embodiment of the present disclosure.
[0118] like Figure 8 As shown, the task execution device 800 may include a removal module 810 , an execution module 820 and an insertion module 830 .
[0119] The removal module 810 is used to determine and remove the target node corresponding to the target thread from the node set in response to determining that the target thread in the process is to execute the target task, wherein the node set includes multiple object nodes, each object node includes an object pointer, and the object pointer points to the address of the object corresponding to the object node in a predetermined storage space.
[0120] The execution module 820 is used to obtain the target object from the object pool corresponding to the node set using the object pointer of the target node, and execute the target task based on the target object.
[0121] The insertion module 830 is used to insert a target node into the node set in response to determining that the target task has been completed.
[0122] According to another embodiment of the present disclosure, the node set also includes a head node, the head node includes calibration information, the object node also includes reference information, and the calibration information of the head node is the same as the reference information of the object node in the target position in the node set; the removal module includes: a removal submodule, which is used to determine the object node in the target position as a target node and remove it in response to determining that the calibration information read at the first moment is the same as the calibration information read at the second moment; wherein the first moment is before the second moment.
[0123] According to another embodiment of the present disclosure, the head node and the object node in the node set form a linked list structure, and the object node of the target position is the object node adjacent to the head node. The removal submodule includes: a first expected value determination unit, a candidate node determination unit, a first update unit, and a second update unit. The first expected value determination unit is used to determine the calibration information read at the first moment as the first expected value. The candidate node determination unit is used to determine the candidate node of the object node at the target position according to the head node. The first update unit is used to respond to determining that the calibration information read at the second moment is inconsistent with the first expected value, update the first expected value using the latest calibration information, and re-determine the candidate node. The second update unit is used to respond to determining that the calibration information read at the second moment is consistent with the first expected value, update the calibration information of the head node using the first new value, determine the candidate node as the target node and remove it, and update the reference information of the target node, wherein the first new value is the reference information of the next object node of the candidate node in the linked list structure.
[0124] According to another embodiment of the present disclosure, the number of node sets is multiple; the first expected value determination unit includes: a first determination subunit and a second determination subunit. The first determination subunit is used to determine a first target node set from the multiple node sets according to the order of the multiple node sets. The second determination subunit is used to determine the calibration information in the first target node set read at the first moment as the first expected value for the first target node set.
[0125] According to another embodiment of the present disclosure, the removal submodule further includes: a trigger unit and an empty set determination unit. The trigger unit is used to trigger the operation of determining the candidate node after determining the first expected value and in response to determining that the first expected value is different from the predetermined value. The empty set determination unit is used to determine that the node set is an empty set in response to determining that the first expected value is the same as the predetermined value after determining the first expected value.
[0126] According to another embodiment of the present disclosure, the node set also includes a head node, the head node includes calibration information, the object node also includes reference information, and the calibration information of the head node is the same as the reference information of the object node in the target position in the node set; the insertion module includes: an insertion sub-module, which is used to insert the target node in the node set based on the target position in response to determining that the calibration information read at the third moment is the same as the calibration information read at the fourth moment; wherein the third moment is before the fourth moment.
[0127] According to another embodiment of the present disclosure, the head node and the object node in the node set form a linked list structure, and the object node of the target position is the object node adjacent to the head node; the insertion submodule includes: a second expected value determination unit, a third update unit and a fourth update unit. The second expected value determination unit is used to determine the calibration information read at the third moment as the second expected value. The third update unit is used to update the second expected value using the latest calibration information in response to determining that the calibration information at the fourth moment is inconsistent with the second expected value, and re-determine whether the calibration information is consistent with the second expected value. The fourth update unit is used to update the calibration information using the second new value in response to determining that the calibration information at the fourth moment is consistent with the second expected value, and insert the target node between the head node and the adjacent object node, and update the reference information of the target node, wherein the second new value is the reference information of the target node.
[0128] According to another embodiment of the present disclosure, the number of node sets is multiple, and the object node further includes: a set identifier of the node set where the object node is located; the second expected value determination unit includes: a third determination subunit and a fourth determination subunit. The third determination subunit is used to determine the second target node set from the multiple node sets according to the set identifier of the node set where the target node is located. The fourth determination subunit is used to determine the calibration information read at the third moment as the second expected value for the second target node set.
[0129] According to another embodiment of the present disclosure, the reference information includes a version number and a node address, the version number is determined based on the number of times the object node is moved, and the node address represents the address of the object node in a predetermined storage space.
[0130] According to another embodiment of the present disclosure, the node address is an offset, wherein the address of the object node in the predetermined storage space is determined based on the offset and the base address.
[0131] According to another embodiment of the present disclosure, the above-mentioned device also includes: a trigger module, a processing module and a first destruction module. The trigger module is used to trigger the removal module to perform its own operation in response to determining that the target thread is to perform the target task and the node set is not an empty set. The processing module is used to generate a target object based on a predetermined method in response to determining that the target thread is to perform the target task and the node set is an empty set, and perform the target task based on the generated target object. The first destruction module is used to destroy the target object in response to determining that the target task has been completed and the target object is generated based on a predetermined method.
[0132] According to another embodiment of the present disclosure, the target object includes data to be read or written, and executing the target task includes: performing a read operation or a write operation on the data to be read or written; or, the target object includes data processing logic, and executing the target task includes: calling the data processing logic to process the data.
[0133] According to another embodiment of the present disclosure, the above-mentioned device further includes: an initialization module and a node set determination module. The initialization module is used to respond to the process startup, initialize the object according to the acquired initialization parameters, and obtain an object pool corresponding to the process. The node set determination module is used to determine the node set according to the object pool.
[0134] According to another embodiment of the present disclosure, the above-mentioned device further includes: a second destruction module, configured to destroy objects in the object pool in response to the end of a process.
[0135] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, comprising at least one processor; and a memory communicatively connected to the at least one processor; the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned task execution method.
[0136] According to an embodiment of the present disclosure, the present disclosure further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the above-mentioned task execution method.
[0137] According to an embodiment of the present disclosure, the present disclosure further provides a computer program product, including a computer program, and the computer program implements the above-mentioned task execution method when executed by a processor.
[0138] Fig. 91 is a block diagram of an electronic device for implementing the task execution method of an embodiment of the present disclosure. 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 may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0139] like Fig. 9 As shown, the device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded from a storage unit 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the device 900 can also be stored. The computing unit 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0140] A number of components in the device 900 are connected to the I / O interface 905, including: an input unit 906, such as a keyboard, a mouse, etc.; an output unit 907, such as various types of displays, speakers, etc.; a storage unit 908, such as a disk, an optical disk, etc.; and a communication unit 909, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 909 allows the device 900 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0141] The computing unit 901 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 901 performs the various methods and processes described above, such as the task execution method. For example, in some embodiments, the task execution method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 908. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 900 via the ROM 902 and / or the communication unit 909. When the computer program is loaded into the RAM 903 and executed by the computing unit 901, one or more steps of the task execution method described above may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to execute the task execution method in any other appropriate manner (e.g., by means of firmware).
[0142] Various implementations 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 chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0143] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0144] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0145] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: 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 can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0146] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0147] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0148] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0149] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A task execution method, comprising: In response to determining that a target thread in a process is to execute a target task, determining and removing a target node corresponding to the target thread from a node set, wherein the node set includes a plurality of object nodes, each object node includes an object pointer, and the object pointer points to an address of an object corresponding to the object node in a predetermined storage space; Using the object pointer of the target node, obtaining a target object from an object pool corresponding to the node set, and executing the target task based on the target object; and In response to determining that the target task has been completed, inserting the target node into the node set.
2. The method according to claim 1, wherein: The node set further includes a head node, the head node includes calibration information, the object node further includes reference information, and the calibration information of the head node is the same as the reference information of the object node at the target position in the node set; Determining and removing the target node corresponding to the target thread from the node set includes: In response to determining that the calibration information read at the first moment is the same as the calibration information read at the second moment, the object node at the target position is determined as the target node and is removed; wherein the first moment is before the second moment.
3. The method according to claim 2, wherein: The head node and the object node in the node set form a linked list structure, and the object node at the target position is an object node adjacent to the head node; The step of determining the object node at the target position as the target node and removing the target node comprises: determining the calibration information read at the first moment as a first expected value; According to the head node, determining the candidate node of the object node at the target position; In response to determining that the calibration information read at the second time is inconsistent with the first expected value, updating the first expected value using the latest calibration information and re-determining the candidate node; and In response to determining that the calibration information read at the second moment is consistent with the first expected value, the calibration information of the head node is updated using a first new value, the candidate node is determined as the target node and removed, and the reference information of the target node is updated, wherein the first new value is the reference information of the next object node of the candidate node in the linked list structure.
4. The method according to claim 3, wherein: The number of the node sets is multiple; and determining the calibration information read at the first moment as the first expected value comprises: Determining a first target node set from the plurality of node sets according to the order of the plurality of node sets; and For the first target node set, the calibration information in the first target node set read at the first moment is determined as the first expected value.
5. The method according to claim 3, wherein the step of determining the object node at the target position as the target node and removing the object node further comprises: After determining the first expected value, In response to determining that the first expected value is different from a predetermined value, triggering an operation of determining a candidate node; as well as In response to determining that the first expected value is the same as a predetermined value, the node set is determined to be an empty set.
6. The method according to claim 1, wherein: The node set further includes a head node, the head node includes calibration information, the object node further includes reference information, and the calibration information of the head node is the same as the reference information of the object node at the target position in the node set; The inserting the target node in the node set comprises: In response to determining that the calibration information read at a third time is the same as the calibration information read at a fourth time, inserting the target node in the node set based on the target ranking; wherein the third time is before the fourth time.
7. The method according to claim 6, wherein: The head node and the object nodes in the node set form a linked list structure, and the object node at the target position is the object node adjacent to the head node; The inserting the target node in the node set based on the target rank comprises: determining the calibration information read at a third time as a second expected value; In response to determining that the calibration information at the fourth time is inconsistent with the second expected value, updating the second expected value using the latest calibration information, and re-determining whether the calibration information is consistent with the second expected value; and In response to determining that the calibration information at the fourth moment is consistent with the second expected value, the calibration information is updated using a second new value, and the target node is inserted between the head node and the adjacent object node, and the reference information of the target node is updated, wherein the second new value is the reference information of the target node.
8. The method according to claim 7, wherein: The number of the node sets is multiple, and the object node further includes: a set identifier of the node set where the object node is located; The step of determining the calibration information read at the third moment as the second expected value comprises: Determining a second target node set from a plurality of node sets according to a set identifier of the node set where the target node is located; and For the second target node set, the calibration information read at the third moment is determined as the second expected value.
9. The method according to claim 2 or 6, wherein: The reference information includes a version number and a node address, wherein the version number is determined based on the number of times the object node is moved, and the node address represents the address of the object node in the predetermined storage space.
10. The method according to claim 9, wherein: The node address is an offset, wherein the address of the object node in the predetermined storage space is determined based on the offset and a base address.
11. The method according to claim 1, further comprising: In response to determining that the target thread is to execute the target task and the node set is not an empty set, triggering an operation of determining and removing a target node corresponding to the target thread from the node set; In response to determining that the target thread is to execute the target task and the node set is an empty set, generating a target object based on a predetermined method, and executing the target task based on the generated target object; as well as In response to determining that the target task has been completed and the target object is generated based on the predetermined manner, destroying the target object.
12. The method according to claim 1, wherein: The target object includes data to be read or written, and executing the target task includes: performing a read operation or a write operation on the data to be read or written; Alternatively, the target object includes data processing logic, and executing the target task includes: calling the data processing logic to process data.
13. The method according to claim 1, further comprising: In response to the process starting, performing object initialization according to the acquired initialization parameters to obtain the object pool corresponding to the process; as well as The node set is determined according to the object pool.
14. The method according to claim 1, further comprising: In response to the process ending, the objects in the object pool are destroyed.
15. A task execution device, comprising: a removal module, configured to determine and remove a target node corresponding to the target thread from a node set in response to determining that the target thread in the process is to execute a target task, wherein the node set includes a plurality of object nodes, each object node includes an object pointer, and the object pointer points to an address of an object corresponding to the object node in a predetermined storage space; an execution module, configured to obtain a target object from an object pool corresponding to the node set using the object pointer of the target node, and execute the target task based on the target object; and The inserting module is used for inserting the target node into the node set in response to determining that the target task has been completed.
16. The device according to claim 15, wherein: The node set further includes a head node, the head node includes calibration information, the object node further includes reference information, and the calibration information of the head node is the same as the reference information of the object node at the target position in the node set; The removal module comprises: The removal submodule is used to determine the object node at the target position as the target node and remove it in response to determining that the calibration information read at the first moment is the same as the calibration information read at the second moment; wherein the first moment is before the second moment.
17. The device according to claim 16, wherein: The head node and the object node in the node set form a linked list structure, and the object node at the target position is an object node adjacent to the head node; The removal submodule comprises: A first expected value determining unit, configured to determine the calibration information read at a first moment as a first expected value; A candidate node determination unit, used for determining a candidate node from the object node at the target position according to the head node; a first updating unit, configured to, in response to determining that the calibration information read at the second time is inconsistent with the first expected value, update the first expected value using the latest calibration information and redetermine the candidate node; and A second updating unit is used for updating the calibration information of the head node with a first new value in response to determining that the calibration information read at the second moment is consistent with the first expected value, determining the candidate node as the target node and removing it, and updating the reference information of the target node, wherein the first new value is the reference information of the next object node of the candidate node in the linked list structure.
18. The device according to claim 17, wherein: The number of the node sets is multiple; the first expected value determination unit includes: a first determining subunit, configured to determine a first target node set from the plurality of node sets according to an order of the plurality of node sets; and The second determining subunit is used to determine, for the first target node set, the calibration information in the first target node set read at the first moment as the first expected value.
19. The device according to claim 17, wherein the removal submodule further comprises: a triggering unit, configured to, after determining the first expected value, trigger an operation of determining a candidate node in response to determining that the first expected value is different from a predetermined value; as well as An empty set determination unit is used to, after determining the first expected value, determine that the node set is an empty set in response to determining that the first expected value is the same as a predetermined value.
20. The device according to claim 15, wherein: The node set further includes a head node, the head node includes calibration information, the object node further includes reference information, and the calibration information of the head node is the same as the reference information of the object node at the target position in the node set; The insertion module comprises: The inserting submodule is used to insert the target node in the node set based on the target ranking in response to determining that the calibration information read at the third time is the same as the calibration information read at the fourth time; wherein the third time is before the fourth time.
21. The device according to claim 20, wherein: The head node and the object nodes in the node set form a linked list structure, and the object node at the target position is the object node adjacent to the head node; The insertion submodule comprises: a second expected value determining unit, configured to determine the calibration information read at a third moment as a second expected value; a third updating unit, configured to, in response to determining that the calibration information at the fourth moment is inconsistent with the second expected value, update the second expected value using the latest calibration information, and re-determine whether the calibration information is consistent with the second expected value; and A fourth updating unit is used to update the calibration information using a second new value in response to determining that the calibration information at the fourth moment is consistent with the second expected value, and to insert the target node between the head node and the adjacent object node to update the reference information of the target node, wherein the second new value is the reference information of the target node.
22. The device according to claim 21, wherein The number of the node sets is multiple, and the object node further includes: a set identifier of the node set where the object node is located; The second expected value determining unit includes: a third determining subunit, configured to determine a second target node set from a plurality of node sets according to a set identifier of the node set where the target node is located; and The fourth determining subunit is used to determine the calibration information read at the third moment as the second expected value for the second target node set.
23. The device according to claim 16 or 20, wherein: The reference information includes a version number and a node address, wherein the version number is determined based on the number of times the object node is moved, and the node address represents the address of the object node in the predetermined storage space.
24. The device according to claim 23, wherein: The node address is an offset, wherein the address of the object node in the predetermined storage space is determined based on the offset and a base address.
25. The apparatus of claim 15, further comprising: A trigger module, configured to trigger the removal module to perform its own operation in response to determining that the target thread is to execute the target task and the node set is not an empty set; A processing module, configured to generate a target object based on a predetermined method in response to determining that the target thread is to execute the target task and the node set is an empty set, and execute the target task based on the generated target object; as well as The first destruction module is configured to destroy the target object in response to determining that the target task has been completed and the target object is generated based on the predetermined method.
26. The device according to claim 15, wherein: The target object includes data to be read or written, and executing the target task includes: performing a read operation or a write operation on the data to be read or written; Alternatively, the target object includes data processing logic, and executing the target task includes: calling the data processing logic to process data.
27. The apparatus of claim 15, further comprising: An initialization module, configured to initialize objects according to the acquired initialization parameters in response to the process startup, and obtain the object pool corresponding to the process; as well as The node set determination module is used to determine the node set according to the object pool.
28. The apparatus of claim 1, further comprising: The second destroying module is used to destroy the objects in the object pool in response to the process ending.
29. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 14.
30. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 14.
31. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 14.
