A lock-free queue optimization method, device, equipment and readable storage medium

By introducing a completion bit into the queue data format and using an auxiliary thread to handle the tail pointer, the data contention problem in the submission phase of a multi-producer or consumer queue is solved, achieving efficient data processing of lock-free queues.

CN115168073BActive Publication Date: 2026-04-07BYZORO NETWORK LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-04
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

When multiple producers or consumers access the queue, existing lock-free queues experience data contention during the commit phase, leading to performance degradation.

Method used

By reserving a bit as a completion bit in the queue data format, the operation of the producer tail pointer and consumer tail pointer is transformed into the detection of the completion bit. An auxiliary thread is used to centrally process the tail pointer of the submission queue, thus avoiding data competition between multiple producers or consumers.

Benefits of technology

It improves the data processing speed of lock-free queues with multiple producers or consumers, reduces data contention, and enhances queue performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115168073B_ABST
    Figure CN115168073B_ABST
Patent Text Reader

Abstract

The application provides a lock-free queue optimization method, device and equipment and a readable storage medium. The method comprises the following steps: obtaining a queue, first information and queue data produced by a producer. The first information comprises a producer head pointer of the queue, a producer tail pointer of the queue and a consumer tail pointer of the queue; one bit of the queue data produced by the producer is used as a completion bit, and the completion bit is set to 0; the queue data produced by the producer is copied to the queue according to the producer head pointer of the queue and the consumer tail pointer of the queue, and the completion bit of the queue data after being copied to the queue is set to 1; whether the completion bit of the queue data pointed to by the current producer tail pointer of the queue is 1 is detected to obtain a first detection result; and whether the queue data produced by the producer is completed in a queue-in operation is judged according to the first detection result. The application realizes the submission of the producer tail pointer / consumer tail pointer through the operation of the completion bit, and solves the data competition in the submission stage.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of data processing, in particular to a lock-free queue optimization method, device, equipment and readable storage medium. BACKGROUND

[0002] In the existing field of data processing, there are generally four kinds of lock-free queues: single producer single consumer queue, multiple producer single consumer queue, single producer multiple consumer queue and multiple producer multiple consumer queue. When multiple producers or multiple consumers simultaneously access the queue, data competition exists in the commit phase, which will cause the overall performance of the queue to decrease with the increase of the number of producers / consumers. Therefore, an optimization method is needed to solve the problem of data competition in the commit phase. SUMMARY

[0003] The purpose of the present application is to provide a lock-free queue optimization method, device, equipment and readable storage medium to improve the above problems.

[0004] In order to achieve the above purpose, the embodiments of the present application provide the following technical solutions:

[0005] On the one hand, the present application provides a lock-free queue optimization method, which comprises:

[0006] obtaining a queue, first information and queue data produced by a producer, wherein the first information comprises a producer head pointer of the queue, a producer tail pointer of the queue and a consumer tail pointer of the queue;

[0007] setting one bit of the queue data produced by the producer as a completion bit, and setting the completion bit to 0;

[0008] copying the queue data produced by the producer to the queue according to the producer head pointer of the queue and the consumer tail pointer of the queue, and setting the completion bit of the queue data produced by the producer after being copied to the queue to 1;

[0009] detecting whether the completion bit of the queue data produced by the producer pointed to by the current producer tail pointer of the queue is 1, to obtain a first detection result;

[0010] judging whether the queue data produced by the producer pointed to by the current producer tail pointer of the queue is completed in the enqueue operation according to the first detection result, and adding 1 to the producer tail pointer of the queue data produced by the producer which is currently completed in the enqueue operation, and then performing the enqueue operation on the next queue data produced by the producer.

[0011] Secondly, the present application provides a lock-free queue optimization device, which comprises:

[0012] The first obtaining module is configured to obtain a queue, first information, and queue data produced by a producer, wherein the first information comprises a producer head pointer of the queue, a producer tail pointer of the queue, and a consumer tail pointer of the queue.

[0013] The first executing module is configured to set one bit of the queue data produced by the producer as a completion bit, and set the completion bit as 0.

[0014] The second executing module is configured to copy the queue data produced by the producer to the queue according to the producer head pointer of the queue and the consumer tail pointer of the queue, and set the completion bit of the queue data produced by the producer after being copied to the queue as 1.

[0015] The first detecting module is configured to detect whether the completion bit of the queue data produced by the producer and pointed to by the current producer tail pointer of the queue is 1, to obtain a first detection result.

[0016] The first judging module is configured to judge, according to the first detection result, whether the queue data produced by the producer and pointed to by the current producer tail pointer of the queue is completed in the enqueuing operation, and add 1 to the producer tail pointer of the queue data produced by the producer which is currently completed in the enqueuing operation, and then perform the enqueuing operation on the next queue data produced by the producer.

[0017] In a third aspect, an embodiment of the present application provides a lock-free queue optimization device, which comprises a memory and a processor. The memory is configured to store a computer program; and the processor is configured to execute the computer program to implement the steps of the above lock-free queue optimization method.

[0018] In a fourth aspect, an embodiment of the present application provides a readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the above lock-free queue optimization method are implemented.

[0019] The present application has the following beneficial effects:

[0020] 1. The present application reserves one bit as a completion bit through format agreement of queue data, minimizes the invasiveness to the data format, and converts the operation of the producer tail pointer of the queue / the consumer tail pointer of the queue in the original submission stage into the operation of the completion bit of the queue data pointed to by the producer tail pointer of the queue / the consumer tail pointer of the queue, thereby avoiding the data competition caused by the competition of the producer tail pointer of the queue / the consumer tail pointer of the queue by multiple producers / consumers in the original submission stage, achieving the purpose of optimizing the lock-free queue of multiple producers / multiple consumers, and improving the data processing speed of the lock-free queue of multiple producers / multiple consumers.

[0021] 2、The application avoids data competition generated by multiple producers / consumers competing for the producer tail pointer / the consumer tail pointer of the submission queue in the submission stage, and improves the performance of the lock-free queue.

[0022] Other features and advantages of the present application will be set forth in the following description, and in part will be apparent from the description, or can be learned by practice of the application. The objects and other advantages of the present application will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings. BRIEF DESCRIPTION OF DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments, and it should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation to the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0024] Figure 1 The flow chart of the lock-free queue optimization method described in the embodiments of the present application.

[0025] Figure 2 The structure schematic diagram of the lock-free queue optimization device described in the embodiments of the present application.

[0026] Figure 3 The structure schematic diagram of the lock-free queue optimization device described in the embodiments of the present application. DETAILED DESCRIPTION

[0027] In order to make the objects, technical solutions and advantages of the embodiments of the present application more clear, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application, and obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.

[0028] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0029] Example 1

[0030] This embodiment provides a lock-free queue optimization method for scenarios where multiple producers / consumers compete to submit the producer tail pointer / consumer tail pointer of the queue during the submission phase of an existing lock-free queue, resulting in data contention.

[0031] like Figure 1 As shown in the figure, the method includes steps S1, S2, S3, S4 and S5.

[0032] Step S1: Obtain the queue, first information, and queue data produced by the producer. The first information includes the producer head pointer, the producer tail pointer, and the consumer tail pointer of the queue.

[0033] In this step, a queue, as a common data structure, is used to temporarily store the queue data generated by the producer. The producer head pointer of the queue points to the currently available position of the producer, the producer tail pointer points to the position of the producer that has not yet committed, and the consumer tail pointer points to the position of the consumer that has not yet committed.

[0034] Step S2: Take one bit of the queue data produced by the producer as the completion bit and set the completion bit to 0;

[0035] In this step, to ensure that the completion bit is 0 before the submission phase, the completion bit of the queue data produced by each producer must first be initialized.

[0036] Step S3: Copy the queue data produced by the producer to the queue according to the producer head pointer and the consumer tail pointer of the queue, and set the completion bit of the queue data produced by the producer after copying to the queue to 1;

[0037] In this step, when the queue data produced by the producer is copied to the queue, if there are multiple producers, the producer tail pointer of the queue needs to be competed, and after the producer tail pointer of the queue is submitted, the producer tail pointer of the queue is increased by 1 to complete the enqueue operation of the queue data produced by the producer. The present application converts the multiple producer tail pointer competition of the queue into the completion bit operation of the queue data pointed to by the producer tail pointer of the queue, and realizes the submission of the producer tail pointer of the queue by detecting the completion bit, thereby effectively solving the data competition problem of the multiple producer tail pointer of the queue.

[0038] Step S4, detecting whether the completion bit of the queue data produced by the producer pointed to by the current producer tail pointer of the queue is 1, to obtain a first detection result;

[0039] Step S5, judging whether the queue data produced by the producer is completed enqueue operation according to the first detection result, and increasing the producer tail pointer of the queue at the queue data produced by the producer which is completed enqueue operation by 1, to perform enqueue operation on the next queue data produced by the producer.

[0040] In the prior art, when the producer submits the producer tail pointer of the queue, it cannot be determined whether there are other producers before itself, so when there are multiple producers, only the "compare and set" in the atomic operation can be used to try to update the producer tail pointer of the queue from the old value to the new value, which affects the performance of the lock-free queue. The "compare and set" in the atomic operation is known to those skilled in the art, and will not be described again.

[0041] Therefore, in this embodiment, by reserving one bit as a completion bit in the format of the queue data produced by the producer, the multiple producer tail pointer competition of the queue in the prior art is effectively converted into the completion bit operation of the queue data pointed to by the producer tail pointer of the queue, thereby effectively avoiding the data competition caused by the multiple producer tail pointer of the queue, improving the performance of the existing multiple producer lock-free queue, and improving the speed of data processing.

[0042] According to the above features, the present embodiment can realize the optimization of the existing lock-free queue in the submission stage, that is, the data competition caused by the multiple producer tail pointer competition of the queue. The method of the present application provides an optimization method for the multiple producer lock-free queue with small data intrusion and fast data processing. The present application can be widely applied to the scene of the multiple producer / multiple consumer lock-free queue.

[0043] In one specific embodiment of the present disclosure, the step S3 can further include steps S31, S32 and S33.

[0044] Step S31, judging whether there is enough space for the queue data produced by the producer to be enqueued according to the producer head pointer of the queue and the consumer tail pointer of the queue, obtaining a first judging result;

[0045] Step S32, obtaining the position information of the queue data produced by the producer in the queue according to the first judging result;

[0046] Step S33, copying the queue data produced by the producer corresponding to the position information into the queue according to the position information.

[0047] In one specific embodiment of the present disclosure, the step S4 can further include steps S41 and S42.

[0048] Step S41, obtaining a submitter, the submitter including an auxiliary thread;

[0049] Step S42, if the producer head pointer of the queue and the producer tail pointer of the queue are not equal, detecting the completion bit of the queue data produced by the producer pointed to by the current producer tail pointer of the queue by the submitter, obtaining the completion bit of the current producer queue data, and judging whether the enqueuing operation of the current queue data is completed according to the completion bit.

[0050] In the present embodiment, by adding a new auxiliary thread as a submitter, the producer tail pointer of the submission queue / the consumer tail pointer of the queue is completed by the submitter, avoiding the data competition caused by the competition of the producer tail pointer of the submission queue / the consumer tail pointer of the queue by multiple producers / consumers in the original submission stage, and improving the performance of the lock-free queue.

[0051] In one specific embodiment of the present disclosure, the step S5 can further include step S51.

[0052] Step S51, judging whether the completion bit is 1, wherein if the completion bit is 1, it is judged that the enqueuing operation of the queue data produced by the current producer is completed, the producer tail pointer of the queue pointing to the queue data produced by the current producer is increased by 1, and the enqueuing operation of the next queue data produced by the producer is performed; if the completion bit is 0, it is judged that the enqueuing operation of the queue data produced by the current producer is not completed, and the completion bit is reconfirmed in the next loop.

[0053] In one specific embodiment of the present disclosure, the step S31 can further include step S311.

[0054] Step S311, judging whether the producer head pointer of the queue plus 1 is not greater than the consumer tail pointer of the queue plus the number of the data produced by the producer, if yes, judging that the space of the queue is enough, and the enqueuing operation of the data produced by the producer can be executed; if not, judging that the space of the queue is not enough, and the enqueuing operation of the data produced by the producer cannot be executed.

[0055] In one specific embodiment of the present disclosure, the step S5 can further comprise steps S6, S7, S8, S9 and S10.

[0056] Step S6, acquiring second information, wherein the second information comprises a consumer head pointer of a queue;

[0057] Step S7, judging whether the queue has enough queue data for the consumer to consume according to the consumer head pointer of the queue and the producer tail pointer of the queue, and obtaining a second judgment result;

[0058] Step S8, copying the queue data consumed by the consumer to the local, and setting the completion position of the queue data consumed by the consumer after dequeuing to 0 according to the second judgment result;

[0059] Step S9, detecting whether the completion bit of the queue data consumed by the consumer is 0, and obtaining a second detection result;

[0060] Step S10, judging whether the queue data consumed by the consumer is completed in the dequeuing operation according to the second detection result, and adding 1 to the consumer tail pointer of the queue data consumed by the consumer which is currently completed in the dequeuing operation, and then performing the dequeuing operation on the next queue data consumed by the consumer.

[0061] In the embodiment, the consumer head pointer of the queue points to the current available position of the consumer, when judging that the queue has enough queue data for the consumer to consume according to the consumer head pointer of the queue and the producer tail pointer of the queue, and copying the queue data in the queue to the local, the completion position of the queue data pointed to by the consumer tail pointer is 0, and the tail pointer of the consumer is added 1 through the detection of the completion bit data by the submitter, so as to complete the dequeuing operation of the queue data consumed by the consumer. Through the conversion of the consumer tail pointer of the submit queue competed by multiple consumers into the detection of the completion bit of the queue data consumed by the consumer by the submitter, the problem of data competition existing in the consumer tail pointer of the submit queue is effectively solved. Therefore, the present application can solve the problem of data competition in the submission stage of the producer tail pointer of the submit queue / consumer tail pointer of the queue in the lock-free queue competition of the multiple producers / multiple consumers, and the data processing speed of the lock-free queue of the multiple producers / multiple consumers is optimized by avoiding the data competition in the submission stage.

[0062] Example 2

[0063] like Figure 2 As shown, this embodiment provides a lock-free queue optimization device, which includes a first acquisition module 901, a first execution module 902, a second execution module 903, a first detection module 904, and a first judgment module 905.

[0064] The first acquisition module 901 is used to acquire the queue, the first information, and the queue data produced by the producer. The first information includes the producer head pointer of the queue, the producer tail pointer of the queue, and the consumer tail pointer of the queue.

[0065] The first execution module 902 is used to take one bit of the queue data produced by the producer as a completion bit and set the completion bit to 0;

[0066] The second execution module 903 is used to copy the queue data produced by the producer to the queue according to the producer head pointer and the consumer tail pointer of the queue, and set the completion bit of the queue data produced by the producer after copying to the queue to 1;

[0067] The first detection module 904 is used to detect whether the completion bit of the queue data produced by the producer pointed to by the tail pointer of the current producer in the queue is 1, and to obtain the first detection result;

[0068] The first judgment module 905 is used to determine, based on the first detection result, whether the queue data produced by the producer pointed to by the current producer tail pointer of the queue has completed the enqueue operation, and increment the producer tail pointer pointing to the queue data produced by the producer that has completed the enqueue operation by 1, and then perform the enqueue operation on the next queue data produced by the producer.

[0069] In one specific embodiment of this disclosure, the second execution module 903 includes a first judgment unit 9031, a determination unit 9032, and an enqueue unit 9033.

[0070] The first judgment unit 9031 is used to determine whether the queue has enough space to enqueue the queue data produced by the producer based on the producer head pointer and the consumer tail pointer of the queue, and to obtain a first judgment result;

[0071] The determining unit 9032 is used to obtain the position information of the queue data produced by the producer in the queue based on the first determination result;

[0072] The enqueue unit 9033 is used to copy the queue data produced by the producer corresponding to the location information into the queue according to the location information.

[0073] In an embodiment of the present disclosure, the first detection module 904 further comprises an acquisition unit 9041 and a second judgment unit 9042.

[0074] The acquisition unit 9041 is configured to acquire a submitter, wherein the submitter comprises an auxiliary thread.

[0075] The second judgment unit 9042 is configured to, if the producer head pointer of the queue and the producer tail pointer of the queue are not equal, detect a completion bit of queue data produced by the producer pointed to by the current producer tail pointer of the queue by the submitter, acquire the completion bit of the queue data produced by the current producer, and determine whether the enqueuing operation of the current queue data is completed according to the completion bit.

[0076] In an embodiment of the present disclosure, the first judgment module 905 comprises a third judgment unit 9051.

[0077] The third judgment unit 9051 is configured to determine whether the completion bit is 1, wherein if the completion bit is 1, it is determined that the enqueuing operation of the queue data produced by the current producer is completed, the producer tail pointer of the queue pointing to the queue data produced by the current producer is incremented by 1, and the enqueuing operation of the next queue data produced by the producer is performed; and if the completion bit is 0, it is determined that the enqueuing operation of the queue data produced by the current producer is not completed, and the data of the completion bit is reconfirmed in the next loop.

[0078] In an embodiment of the present disclosure, the first judgment unit 9031 comprises a sub-judgment unit 90311.

[0079] The sub-judgment unit 90311 is configured to determine whether the producer head pointer of the queue incremented by 1 is not greater than the consumer tail pointer of the queue incremented by the number of data produced by the producer, wherein if yes, it is determined that the space of the queue is sufficient, and the enqueuing operation of the data produced by the producer can be performed; and if not, it is determined that the space of the queue is insufficient, and the enqueuing operation of the data produced by the producer cannot be performed.

[0080] In an embodiment of the present disclosure, the device further comprises a second acquisition module 906, a second judgment module 907, a dequeuing module 908, a second detection module 909 and a third judgment module 910.

[0081] The second acquisition module 906 is configured to acquire second information, wherein the second information comprises a consumer head pointer of a queue.

[0082] The second judging module 907 is configured to judge whether there is enough queue data for the consumer to consume according to the consumer head pointer of the queue and the producer tail pointer of the queue, to obtain a second judging result.

[0083] The dequeuing module 908 is configured to copy the queue data consumed by the consumer to the local device according to the second judging result, and then set the completion position of the queue data consumed by the consumer after dequeuing to 0.

[0084] The second detecting module 909 is configured to detect whether the completion bit of the queue data consumed by the consumer is 0, to obtain a second detecting result.

[0085] The third judging module 910 is configured to judge whether the queue data consumed by the consumer is completed in the dequeuing operation according to the second detecting result, and add 1 to the consumer tail pointer of the queue data consumed by the consumer which is currently completed in the dequeuing operation, and then perform the dequeuing operation on the next queue data consumed by the consumer.

[0086] It should be noted that, as to the apparatus in the above-described embodiments, the specific manners in which various modules perform operations have been described in detail in the embodiments of the method, and thus will not be described here in detail.

[0087] Embodiment 3

[0088] Corresponding to the above method embodiments, the embodiments of the present disclosure also provide a lock-free queue optimization device. The lock-free queue optimization device described below can be mutually referred to with the lock-free queue optimization method described above.

[0089] Figure 3 is a block diagram of a lock-free queue optimization device 800 according to an exemplary embodiment. As shown in Figure 3 The lock-free queue optimization device 800 can include a processor 801 and a memory 802. The lock-free queue optimization device 800 can also include one or more of a multimedia component 803, an input / output (I / O) interface 804, and a communication component 805.

[0090] The processor 801 is configured to control overall operations of the lock-free queue optimization device 800 to complete all or part of the steps of the above-mentioned lock-free queue optimization method. The memory 802 is configured to store various types of data to support the operations of the lock-free queue optimization device 800, which can include, for example, instructions for any application or method operating on the lock-free queue optimization device 800, and application-related data, such as contact data, sent and received messages, pictures, audio, video, and the like. The memory 802 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The multimedia component 803 can include a screen and an audio component. The screen can be a touch screen, for example, and the audio component is configured to output and / or input audio signals. For example, the audio component can include a microphone configured to receive external audio signals. The received audio signals can be further stored in the memory 802 or transmitted through the communication component 805. The audio component also includes at least one speaker configured to output audio signals. The I / O interface 804 provides an interface between the processor 801 and other interface modules, which can be a keyboard, a mouse, a button, and the like. The buttons can be virtual buttons or physical buttons. The communication component 805 is configured to perform wired or wireless communication between the lock-free queue optimization device 800 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, near field communication (NFC), 2G, 3G or 4G, or a combination of one or more of them, so the corresponding communication component 805 can include a Wi-Fi module, a Bluetooth module, an NFC module.

[0091] In an example embodiment, the lock-free queue optimization device 800 can be implemented by one or more Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), controller, microcontroller, microprocessor or other electronic devices to execute the above-described lock-free queue optimization method.

[0092] In another example embodiment, a computer-readable storage medium including program instructions that, when executed by a processor, implement the steps of the above-described lock-free queue optimization method is also provided. For example, the computer-readable storage medium can be the above-described memory 802 including program instructions that can be executed by the processor 801 of the lock-free queue optimization device 800 to complete the above-described lock-free queue optimization method.

[0093] Corresponding to the above method embodiments, the embodiments of the present disclosure also provide a readable storage medium, and the readable storage medium described below can be referred to each other corresponding to the above-described lock-free queue optimization method.

[0094] Embodiment 4

[0095] A readable storage medium, on which a computer program is stored, the computer program being executed by a processor to implement the steps of the lock-free queue optimization method of the above-described method embodiments.

[0096] The readable storage medium can specifically be a U disk, a mobile hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and various readable storage media that can store program codes.

[0097] The above only describes the preferred embodiments of the present disclosure and is not used to limit the present disclosure. For those skilled in the art, the present disclosure can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

[0098] The above merely illustrates the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of the changes or replacements within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A lock-free queue optimization method, characterized in that, include: Get the queue, the first information, and the queue data produced by the producer. The first information includes the producer head pointer, the producer tail pointer, and the consumer tail pointer of the queue. Use one bit of the queue data produced by the producer as the completion bit, and set the completion bit to 0; The queue data produced by the producer is copied to the queue according to the producer head pointer and the consumer tail pointer of the queue, and the completion bit of the queue data produced by the producer after being copied to the queue is set to 1; The first detection result is obtained by checking whether the completion bit of the queue data produced by the producer pointed to by the tail pointer of the current producer in the queue is 1. Based on the first detection result, determine whether the queue data produced by the producer currently pointed to by the producer tail pointer has completed the enqueue operation, and increment the producer tail pointer pointing to the queue data produced by the producer that has completed the enqueue operation by 1, and then perform the enqueue operation on the next queue data produced by the producer.

2. The lock-free queue optimization method according to claim 1, characterized in that, Copying queue data produced by the producer to the queue based on the producer head pointer and the consumer tail pointer of the queue includes: Based on the producer head pointer and the consumer tail pointer of the queue, determine whether the queue has enough space to enqueue the queue data produced by the producer, and obtain the first judgment result; Based on the first judgment result, the position information of the queue data produced by the producer in the queue is obtained; Based on the location information, copy the queue data produced by the producer corresponding to the location information into the queue.

3. The lock-free queue optimization method according to claim 1, characterized in that, The step of detecting whether the completion bit of the queue data produced by the producer pointed to by the tail pointer of the current producer in the queue is 1, to obtain the first detection result, includes: Obtain the submitter, which includes an auxiliary thread; If the producer head pointer and the producer tail pointer of the queue are not equal, the submitter checks the completion bit of the queue data produced by the producer pointed to by the current producer tail pointer, obtains the completion bit of the current producer's queue data, and determines whether the enqueue operation of the current queue data is completed based on the completion bit.

4. The lock-free queue optimization method according to claim 1, characterized in that, The step of determining whether the queue data produced by the producer pointed to by the tail pointer of the current producer in the queue has completed the enqueue operation based on the first detection result includes: Determine whether the completion bit is 1. If the completion bit is 1, it is determined that the enqueue operation of the queue data produced by the current producer is completed, and the producer tail pointer of the queue pointing to the queue data produced by the current producer is incremented by 1, and the enqueue operation of the queue data produced by the next producer is performed. If the completion bit is 0, it is determined that the enqueue operation of the queue data produced by the current producer is not completed, and the data of the completion bit is reconfirmed in the next loop.

5. A lock-free queue optimization device, characterized in that, include: The first acquisition module is used to acquire the queue, the first information, and the queue data produced by the producer. The first information includes the producer head pointer, the producer tail pointer, and the consumer tail pointer of the queue. The first execution module is used to take one bit of the queue data produced by the producer as a completion bit and set the completion bit to 0; The second execution module is used to copy the queue data produced by the producer to the queue according to the producer head pointer and the consumer tail pointer of the queue, and set the completion bit of the queue data produced by the producer after copying to the queue to 1; The first detection module is used to detect whether the completion bit of the queue data produced by the producer pointed to by the tail pointer of the current producer in the queue is 1, and to obtain the first detection result. The first judgment module is used to determine, based on the first detection result, whether the queue data produced by the producer pointed to by the current producer tail pointer of the queue has completed the enqueue operation, and increments the producer tail pointer pointing to the queue data produced by the producer that has completed the enqueue operation by 1, and then performs the enqueue operation on the next queue data produced by the producer.

6. The lock-free queue optimization device according to claim 5, characterized in that, The second execution module includes: The first judgment unit is used to determine whether the queue has enough space to enqueue the queue data produced by the producer based on the producer head pointer and the consumer tail pointer of the queue, and to obtain the first judgment result. The determining unit is used to obtain the position information of the queue data produced by the producer in the queue based on the first determination result; The enqueue unit is used to copy the queue data produced by the producer corresponding to the location information into the queue according to the location information.

7. The lock-free queue optimization device according to claim 5, characterized in that, The first detection module includes: An acquisition unit is used to acquire the submitter, wherein the submitter includes an auxiliary thread; The second judgment unit is used to detect the completion bit of the queue data produced by the producer pointed to by the current producer tail pointer if the producer head pointer and the producer tail pointer of the queue are not equal, and obtain the completion bit of the current producer's queue data, and determine whether the enqueue operation of the current queue data is completed based on the completion bit.

8. The lock-free queue optimization device according to claim 5, characterized in that, The first judgment module includes: The third judgment unit is used to determine whether the completion bit is 1. If the completion bit is 1, it is determined that the enqueue operation of the queue data produced by the current producer is completed, and the producer tail pointer of the queue pointing to the queue data produced by the current producer is incremented by 1, and the enqueue operation of the queue data produced by the next producer is performed. If the completion bit is 0, it is determined that the enqueue operation of the queue data produced by the current producer is not completed, and the data of the completion bit is reconfirmed in the next loop.

9. A queue-free optimization device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the lock-free queue optimization method as described in any one of claims 1 to 4 when executing the computer program.

10. A readable storage medium, characterized in that: The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the lock-free queue optimization method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Queue data access method and device and electronic equipment

    CN110362348A

  • Method and apparatus for lockless communication between cores in a multi-core processor

    US20110296437A1