Method and device for optimizing queue spin lock in high-concurrency scene

By configuring the equal lock time for the spin lock request node and optimizing the waiting queue, the problem of too long spin waiting time caused by the queue spin lock is solved, and the performance and resource utilization of the operating system are improved.

CN120407242AInactive Publication Date: 2025-08-01WEAPON EQUIP RES INST OF CHINA NAT WEAPON EQUIP GRP
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510929041.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-07
Publication Date
2025-08-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In high concurrency scenarios, the queueing mechanism of queue spin lock causes the node spin waiting time to be too long, resulting in a degradation of the overall performance of the operating system.

Method used

Configure the equal lock duration for the spin lock request node, and optimize the waiting queue through the red and black tree structure, insert the queue according to the time of the time of the spin lock to ensure that nodes with shorter lock time will be given priority in obtaining the spin lock.

Benefits of technology

Reduce unnecessary spin states, improve the usage efficiency of multi-core CPUs, improve the overall performance and resource utilization of the operating system, and is adaptable and thread-safe.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407242A_ABST
    Figure CN120407242A_ABST
Patent Text Reader

Abstract

The invention discloses a method and a device for optimizing a queue spin lock in a high-concurrency scene, and belongs to the technical field of operating systems. The method comprises the following steps: configuring an equal lock duration for a request node applying for a spin lock; determining the occupancy condition of the spin lock based on the global identification bit; when the spin lock is occupied, whether a spin lock succession node corresponding to the spin lock is empty or not is determined based on the first judgment identification bit; when the request node is empty, the request node is used as a spin lock succession node, and the spin lock succession node spins to wait for the spin lock to be released; when the spin lock is not empty, a waiting queue corresponding to the spin lock is obtained, and each non-queue-tail node in the waiting queue spins and waits to become a queue-tail node; waiting for a queue tail node of the queue to spin and wait to become a spin lock succession node, and waiting for the spin lock to release by the spin lock succession node. According to the invention, the overall performance and the resource utilization rate of the operating system in the multi-core processor environment are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of operating systems, and in particular, relates to an optimization method and device for a queue spin lock in a high-concurrency scenario. Background Art

[0002] The queue spin lock in the operating system has improvements over the spin lock when dealing with high-concurrency scenarios. For example, in the slow path and the contended queue state, the node that acquires the spin lock will enter the waiting queue. The waiting queue is a first-in-first-out queue, and the newly added node to the queue is at the head of the queue. The node at the end of the queue, that is, the successor node, is removed from the queue while obtaining the lock and becomes the spin lock holder. The lock-holding node sets the global lock bit to 1 and sets the lock bit of the successor node to 0, notifying the successor node to become the new successor. At this time, the applicant at the new end of the queue becomes the new successor, and the successor spins and waits on the global lock bit. The new successor will immediately obtain the lock after the current holder releases the spin lock and becomes the lock holder. The other nodes in the queue spin and wait on the local lock bit until they become the successor.

[0003] The fairness is ensured through the queuing mechanism. The nodes in the waiting queue spin on the local lock bit, which improves the cache hit rate, reduces cache thrashing, and improves the system performance. However, the queuing mechanism leads to another problem, that is, the newly enqueued node will not exit the spin state and execute the task code until all the predecessor nodes release the lock. If the lock time of the predecessor node is very long, it will cause the spin waiting time of the successor node to be much longer than its task execution time, resulting in a decline in the overall performance of the operating system. Summary of the Invention

[0004] The present invention proposes an optimization method and device for a queue spin lock in a high-concurrency scenario to solve the above technical problem of the decline in the overall performance of the operating system.

[0005] In a first aspect of the present invention, an optimization method for a queue spin lock in a high-concurrency scenario is proposed, and the method includes: Step S1: Configure a waiting lock duration for the requesting node that applies for the spin lock; determine the occupancy of the spin lock based on the global identification bit; When the spin lock is occupied, determine whether the spin lock successor node corresponding to the spin lock is empty based on the first judgment identification bit. The spin lock successor node is the requesting node that immediately occupies the spin lock after the spin lock is released; when the spin lock successor node is empty, enter Step S2; when the spin lock successor node is not empty, enter Step S3; Step S2: Take the requesting node as the spin lock successor node, and mark the first judgment flag as the spin lock successor node not being empty; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag as the spin lock successor node being empty, and the method ends; Step S3: Obtain the waiting queue corresponding to the spin lock, where the waiting queue is used to save other requesting nodes that apply for the spin lock, and specifically: If the waiting queue is empty, create a waiting queue and take the requesting node as the tail node of the waiting queue; If the waiting queue is not empty, take the requesting node as the newly added requesting node, determine the queue position of the newly added requesting node based on the waiting time for the lock of the newly added requesting node, and insert the newly added requesting node into the waiting queue; Among them, the waiting queue is a queue with the tail first out; each non-tail node in the waiting queue spins and waits to become the tail node; the tail node of the waiting queue spins and waits for the first judgment flag to be marked as the spin lock successor node being empty. When the first judgment flag is marked as the spin lock successor node being empty, the tail node dequeues and becomes the spin lock successor node; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag as the spin lock successor node being empty.

[0006] Preferably, the waiting time for the lock is a parameter of the data structure of the requesting node, and the waiting time for the lock is configured in the form of a parameter.

[0007] Preferably, when the spin lock is not occupied, the requesting node directly obtains the spin lock and sets the global flag to 1, where 1 represents that the spin lock is occupied.

[0008] Preferably, the data structure of the waiting queue is a red-black tree, and the tail is the leftmost leaf node of the leftmost subtree of the red-black tree. The method for adding a newly added requesting node in the red-black tree is as follows: Traverse the red-black tree to determine the predecessor node whose waiting time for the lock is less than or equal to that of the newly added requesting node, and the successor node whose waiting time for the lock is greater than that of the newly added requesting node, and the predecessor node and the successor node are adjacent nodes in the red-black tree; insert the newly added requesting node between the predecessor node and the successor node, and then readjust the positions of each requesting node in the red-black tree based on the data structure constraints of the red-black tree.

[0009] Preferably, if the waiting queue is not empty, take the requesting node as the newly added requesting node, determine the queue position of the newly added requesting node based on the waiting time for the lock of the newly added requesting node, and insert the newly added requesting node into the waiting queue, where: If the equal lock waiting duration of the newly added request node is less than that of the tail node of the waiting queue, modify the equal lock waiting duration of the newly added request node to be the equal lock waiting duration of the tail node of the waiting queue plus 1, determine the queue position of the newly added request node based on the modified equal lock waiting duration of the newly added request node, and insert the newly added request node into the waiting queue.

[0010] The second aspect of the present invention proposes an optimized device for queue spin locks in a high-concurrency scenario. The device includes: Judgment module: Configure an equal lock waiting duration for the request node applying for the spin lock; determine the occupancy situation of the spin lock based on the global flag bit; When the spin lock is occupied, determine whether the spin lock successor node corresponding to the spin lock is empty based on the first judgment flag bit. The spin lock successor node is the request node that immediately occupies the spin lock after the spin lock is released; when the spin lock successor node is empty, trigger the first processing module; when the spin lock successor node is not empty, trigger the second processing module; First processing module: Take the request node as the spin lock successor node, and mark the first judgment flag bit as the spin lock successor node not being empty; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag bit as the spin lock successor node being empty; Second processing module: Obtain the waiting queue corresponding to the spin lock. The waiting queue is used to save other request nodes applying for the spin lock, where: If the waiting queue is empty, create a waiting queue and take the request node as the tail node of the waiting queue; If the waiting queue is not empty, take the request node as the newly added request node, determine the queue position of the newly added request node based on the equal lock waiting duration of the newly added request node, and insert the newly added request node into the waiting queue; Among them, the waiting queue is a tail-first-out queue; each non-tail node in the waiting queue spins and waits to become the tail node; the tail node of the waiting queue spins and waits for the first judgment flag bit to be marked as the spin lock successor node being empty. When the first judgment flag bit is marked as the spin lock successor node being empty, the tail node dequeues and becomes the spin lock successor node; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag bit as the spin lock successor node being empty.

[0011] The third aspect of the present invention provides an electronic device. The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; where, 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 execute the method as described above.

[0012] A fourth aspect of the present invention provides a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the method as described above.

[0013] The present invention has the following technical effects: (1) By optimizing the lock queuing mechanism, unnecessary spin states are reduced, the utilization efficiency of multi-core CPUs is provided, and the overall performance and resource utilization rate of the operating system in a multi-core processor environment are improved.

[0014] (2) Adaptive adjustment is made according to different workloads and scenarios, and it has strong adaptability and scalability.

[0015] (3) The present invention ensures that all operations of inserting into, dequeuing from, and waking up subsequent nodes of the waiting queue are thread-safe through a lock mechanism or an RCU mechanism. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a schematic flowchart of an optimization method for a queue spin lock in a high-concurrency scenario of the present invention. DETAILED DESCRIPTION

[0017] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are some but not all of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.

[0018] As Figure 1 shown, the present invention provides an optimization method for a queue spin lock in a high-concurrency scenario, and the method includes: Step S1: Configure a waiting lock duration for a request node applying for a spin lock; determine the occupancy of the spin lock based on a global flag bit; When the spin lock is occupied, determine whether the spin lock successor node corresponding to the spin lock is empty based on a first judgment flag bit, where the spin lock successor node is the request node that immediately occupies the spin lock after the spin lock is released; when the spin lock successor node is empty, proceed to step S2; when the spin lock successor node is non-empty, proceed to step S3; Step S2: Use the requesting node as the spin lock successor node, and mark the first judgment flag as the spin lock successor node not being empty; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag as the spin lock successor node being empty, and the method ends; Step S3: Obtain the waiting queue corresponding to the spin lock, where the waiting queue is used to save other requesting nodes that apply for the spin lock, and specifically: If the waiting queue is empty, create a waiting queue and use the requesting node as the tail node of the waiting queue; If the waiting queue is not empty, use the requesting node as a new requesting node, determine the queue position of the new requesting node based on the spin lock waiting duration of the new requesting node, and insert the new requesting node into the waiting queue; Among them, the waiting queue is a tail-first-out queue; each non-tail node in the waiting queue spins and waits to become the tail node; the tail node of the waiting queue spins and waits for the first judgment flag to be marked as the spin lock successor node being empty. When the first judgment flag is marked as the spin lock successor node being empty, the tail node dequeues and becomes the spin lock successor node; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag as the spin lock successor node being empty.

[0019] The spin lock waiting duration is a parameter of the data structure of the requesting node, and the spin lock waiting duration is configured in the form of a parameter. The spin lock waiting duration specifies the maximum waiting duration of the requesting node when the spin lock applied for by the requesting node is occupied.

[0020] The unit of the spin lock waiting duration is the CPU single instruction execution time or the CPU single instruction execution cycle. In the present invention, the spin lock waiting duration can be estimated by the average number of instructions executed by the CPU during the lock-holding stage of the thread. When spinning, after spinning a complete spin cycle, calculate the value corresponding to subtracting 1 from the spin lock waiting duration, and update the spin lock waiting duration to this value; after the spin lock waiting duration is updated to 0, the spin lock waiting duration is no longer updated.

[0021] When the spin lock is not occupied, the requesting node directly obtains the spin lock and sets the global flag to 1, where 1 represents that the spin lock is occupied.

[0022] The data structure of the waiting queue is a red-black tree, and the tail is the leftmost leaf node of the leftmost subtree of the red-black tree. The method for adding a new requesting node in the red-black tree is: Traverse the red - black tree to determine the predecessor node whose waiting lock duration is less than or equal to that of the newly added request node, and the successor node whose waiting lock duration is greater than that of the newly added request node, and the predecessor node and the successor node are adjacent nodes in the red - black tree; insert the newly added request node between the predecessor node and the successor node, and then readjust the positions of each request node in the red - black tree based on the data structure constraints of the red - black tree.

[0023] Further, if the waiting queue is not empty, use the request node as the newly added request node, determine the queue position of the newly added request node based on the waiting lock duration of the newly added request node, and insert the newly added request node into the waiting queue, where: If the waiting lock duration of the newly added request node is less than the waiting lock duration of the tail node of the waiting queue, modify the waiting lock duration of the newly added request node to be the waiting lock duration of the tail node of the waiting queue plus 1, determine the queue position of the newly added request node based on the modified waiting lock duration of the newly added request node, and insert the newly added request node into the waiting queue.

[0024] In the present invention, when the global flag indicates that the spin lock is released, the spin lock successor node directly obtains the spin lock, and the global flag is set to 1.

[0025] In the present invention, the request node with less waiting lock time is inserted into a position closer to the tail of the queue, so this request node will obtain the spin lock faster. This ensures that the node with a short waiting lock time obtains the lock first. Reducing the waiting lock time of all request nodes within each spin cycle will ensure that all request nodes can obtain the lock and will not wait indefinitely.

[0026] The following describes the apparatus for implementing the present invention. For its specific implementation process and technical effects, refer to the above, and will not be elaborated below.

[0027] Optionally, the present invention provides an optimized apparatus for queue spin locks in a high - concurrency scenario. The apparatus includes: A judgment module: configure the waiting lock duration for the request node applying for the spin lock; determine the occupancy of the spin lock based on the global flag; When the spin lock is occupied, determine whether the spin lock successor node corresponding to the spin lock is empty based on the first judgment flag. The spin lock successor node is the request node that immediately occupies the spin lock after the spin lock is released; when the spin lock successor node is empty, trigger the first processing module; when the spin lock successor node is non - empty, trigger the second processing module; The first processing module: use the request node as the spin lock successor node, and mark the first judgment flag as the spin lock successor node being non - empty; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag as the spin lock successor node being empty; Second processing module: Obtain the wait queue corresponding to the spin lock, where the wait queue is used to save other request nodes that apply for the spin lock, and: If the wait queue is empty, create a wait queue and use the request node as the tail node of the wait queue; If the wait queue is not empty, use the request node as a new request node, determine the queue position of the new request node based on the lock waiting duration of the new request node, and insert the new request node into the wait queue; Among them, the wait queue is a queue with the tail node first out; each non-tail node in the wait queue spins and waits to become the tail node; the tail node of the wait queue spins and waits for the first judgment flag bit to be marked that the spin lock successor node is empty. When the first judgment flag bit is marked that the spin lock successor node is empty, the tail node dequeues and serves as the spin lock successor node; the spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, the first judgment flag bit is marked that the spin lock successor node is empty.

[0028] The above modules can be one or more integrated circuits configured to implement the above methods. For example: one or more application specific integrated circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more field programmable gate arrays (FPGAs), etc. Again, when a certain above module is implemented in the form of a processing element scheduling program code, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program code. Again, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0029] The above modules can be connected or communicate with each other via wired connections or wireless connections. Wired connections can include metal cables, optical cables, hybrid cables, etc., or any combination thereof. Wireless connections can include connections in the form of LAN, WAN, Bluetooth, ZigBee, or NFC, etc., or any combination thereof. Two or more modules can be combined into a single module, and any one module can be divided into two or more units. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described systems and devices can refer to the corresponding processes in the method embodiments, and will not be elaborated in the present invention.

[0030] It should be noted that the above modules can be one or more integrated circuits configured to implement the above methods. For example: one or more Application Specific Integrated Circuits (ASICs), or, one or more Digital Signal Processors (DSPs), or, one or more Field Programmable Gate Arrays (FPGAs), etc. Another example is that when a certain module above is implemented in the form of a processing element scheduling program code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processors that can call program code. Another example is that these modules can be integrated together and implemented in the form of a System-on-a-chip (SOC).

[0031] The electronic device includes a processor, a memory, a communication interface, a display screen, and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with external terminals in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a carrier network, Near Field Communication (NFC), or other technologies. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the electronic device, or an external keyboard, touchpad, or mouse, etc.

[0032] The present invention also provides a program product, such as a computer-readable storage medium, including a program that is used to execute the above method embodiments when executed by a processor.

[0033] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of the devices or units can be in electrical, mechanical, or other forms.

[0034] The unit described as a separation component may or may not be physically separated. The component shown as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed across multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0035] In addition, each functional unit in various embodiments of the present invention may be integrated in a processing unit, may exist separately as individual physical units, or two or more units may be integrated in one unit. The above integrated unit may be implemented in the form of hardware, or in the form of a combination of hardware and software functional units.

[0036] The above integrated unit implemented in the form of a software functional unit may be stored in a computer-readable storage medium. The above software functional unit stored in a storage medium includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to execute some steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc that can store program codes.

Claims

1. An optimization method for queue spin locks in high-concurrency scenarios, characterized in that, The method includes: Step S1: Configure an equal lock duration for the requesting node applying for the spin lock; determine the occupancy of the spin lock based on the global flag bit; When the spin lock is occupied, determine whether the spin lock successor node corresponding to the spin lock is empty based on the first judgment flag bit. The spin lock successor node is the requesting node that immediately occupies the spin lock after the spin lock is released. When the spin lock successor node is empty, proceed to Step S2; when the spin lock successor node is not empty, proceed to Step S3; Step S2: Take the requesting node as the spin lock successor node, and mark the first judgment flag bit as the spin lock successor node not being empty. The spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag bit as the spin lock successor node being empty, and the method ends; Step S3: Obtain the waiting queue corresponding to the spin lock. The waiting queue is used to save other requesting nodes applying for the spin lock, where: If the waiting queue is empty, create a waiting queue and take the requesting node as the tail node of the waiting queue; If the waiting queue is not empty, take the requesting node as the newly added requesting node, determine the queue position of the newly added requesting node based on the equal lock duration of the newly added requesting node, and insert the newly added requesting node into the waiting queue; Among them, the waiting queue is a last-in-first-out queue; each non-tail node in the waiting queue spins and waits to become the tail node; the tail node of the waiting queue spins and waits for the first judgment flag bit to be marked as the spin lock successor node being empty. When the first judgment flag bit is marked as the spin lock successor node being empty, the tail node dequeues and becomes the spin lock successor node. The spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag bit as the spin lock successor node being empty.

2. The method according to claim 1, wherein The equal lock duration is a parameter of the data structure of the requesting node, and the equal lock duration is configured in the form of a parameter.

3. The method according to claim 1, wherein When the spin lock is not occupied, the requesting node directly obtains the spin lock and sets the global flag bit to 1, where 1 represents the spin lock being occupied.

4. The method according to claim 1, characterized in that The data structure of the waiting queue is a red-black tree, and the tail is the leftmost leaf node of the leftmost subtree of the red-black tree. The method for adding a newly added requesting node to the red-black tree is: Traverse the red-black tree to determine the predecessor node whose equal lock duration is less than or equal to that of the newly added requesting node, the successor node whose equal lock duration is greater than that of the newly added requesting node, and the predecessor node and the successor node are adjacent nodes in the red-black tree; insert the newly added requesting node between the predecessor node and the successor node, and then readjust the positions of each requesting node in the red-black tree based on the data structure constraints of the red-black tree.

5. The method according to claim 1, characterized in that, If the waiting queue is not empty, take the requesting node as the newly added requesting node, determine the queue position of the newly added requesting node based on the equal lock duration of the newly added requesting node, and insert the newly added requesting node into the waiting queue, where: If the equal lock waiting duration of the newly added request node is less than that of the tail node of the waiting queue, modify the equal lock waiting duration of the newly added request node to be the equal lock waiting duration of the tail node of the waiting queue plus 1, determine the queue position of the newly added request node based on the modified equal lock waiting duration of the newly added request node, and insert the newly added request node into the waiting queue.

6. An optimization device for queue spin locks in a high-concurrency scenario, characterized in that, The device includes: A judgment module: Configure an equal lock waiting duration for a request node applying for a spin lock; Determine the occupancy status of the spin lock based on a global flag bit; When the spin lock is occupied, determine whether the spin lock successor node corresponding to the spin lock is empty based on a first judgment flag bit, where the spin lock successor node is the request node that immediately occupies the spin lock after the spin lock is released; When the spin lock successor node is empty, trigger a first processing module; When the spin lock successor node is not empty, trigger a second processing module; The first processing module: Use the request node as the spin lock successor node, and mark the first judgment flag bit as the spin lock successor node not being empty; The spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag bit as the spin lock successor node being empty; The second processing module: Obtain the waiting queue corresponding to the spin lock, where the waiting queue is used to store other request nodes applying for the spin lock, and among them: If the waiting queue is empty, create a waiting queue and use the request node as the tail node of the waiting queue; If the waiting queue is not empty, use the request node as the newly added request node, determine the queue position of the newly added request node based on the equal lock waiting duration of the newly added request node, and insert the newly added request node into the waiting queue; Among them, the waiting queue is a tail-first-out queue; Each non-tail node in the waiting queue spins and waits to become the tail node; The tail node of the waiting queue spins and waits for the first judgment flag bit to be marked as the spin lock successor node being empty, and when the first judgment flag bit is marked as the spin lock successor node being empty, the tail node dequeues and serves as the spin lock successor node; The spin lock successor node spins and waits for the spin lock to be released, and after the spin lock successor node occupies the spin lock, mark the first judgment flag bit as the spin lock successor node being empty.

7. An electronic device, characterized in that, The device includes: At least one processor; and A memory communicatively connected to the at least one processor; where, 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 according to any one of claims 1-5.

8. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-5.

Citation Information

Patent Citations

  • Large critical region protection method

    CN102141932A

  • Spin lock acquisition method and apparatus

    CN104932933A

  • Implementation method of spin lock as multi-core CPU accessing resources

    CN107357648A

  • A method and device for acquiring a spin lock

    CN109558241A