CN110134439B - Lock-free data structure construction method and data writing and reading methods - Google Patents

Lock-free data structure construction method and data writing and reading methods Download PDF

Info

Publication number
CN110134439B
CN110134439B CN201910253786.0A CN201910253786A CN110134439B CN 110134439 B CN110134439 B CN 110134439B CN 201910253786 A CN201910253786 A CN 201910253786A CN 110134439 B CN110134439 B CN 110134439B
Authority
CN
China
Prior art keywords
queue
data
cursor
producer
consumer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910253786.0A
Other languages
Chinese (zh)
Other versions
CN110134439A (en
Inventor
刘靖非
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baizhuo Network Technology Co ltd
Original Assignee
Beijing Baizhuo Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baizhuo Network Technology Co ltd filed Critical Beijing Baizhuo Network Technology Co ltd
Priority to CN201910253786.0A priority Critical patent/CN110134439B/en
Publication of CN110134439A publication Critical patent/CN110134439A/en
Application granted granted Critical
Publication of CN110134439B publication Critical patent/CN110134439B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline, look ahead
    • G06F9/3854Instruction completion, e.g. retiring, committing or graduating
    • G06F9/3856Reordering of instructions, e.g. using queues or age tags

Abstract

The application provides a lock-free data structure construction method and a method for writing data and reading data, wherein the construction method comprises the following steps: setting a data queue, wherein the data queue comprises a queue body; dividing the queue body into a plurality of queue elements which are sequentially and continuously arranged, and sequentially recording each queue element by adopting a numerical sequence according to the time sequence of the queue element entering the queue body; generating a production progress vernier of a producer writing data into the queue body according to the number sequence number of the queue element at the head of the queue body; and generating a consumption progress cursor of a consumer reading data from the queue body according to the number sequence number of the queue element at the tail part of the queue body. The data queue constructed by the construction method has high data processing speed and is beneficial to improving the performance of a computer.

Description

Lock-free data structure construction method and data writing and reading methods
Technical Field
The present application relates to the field of data processing, and in particular, to a lock-free data structure construction method and a method for writing data into and reading data from the data structure.
Background
Computers need to process large amounts of data, and how to efficiently implement storage and organization of data is an important issue.
To increase the processing speed of data, a multithread technology may be used to perform concurrent operations on data (e.g., write data and read data, etc.), and to ensure the security and validity of data during concurrent operations, various lock operations are usually required, for example, when there are a large number of concurrent read/write access requests for data, a mutual exclusion lock is used to ensure the consistency of data. However, the use of a large number of lock operations may cause the thread to stop or sleep, thereby causing a delay in data access requests and reducing data processing speed.
Therefore, how to increase the processing speed of data when there are multiple concurrent access requests is a problem to be solved.
Disclosure of Invention
In view of the above, the present application provides a method for constructing a lock-free data structure and a method for writing data and reading data, so as to increase the processing speed of data.
In a first aspect, the present invention provides a method for constructing a lock-free data structure, where the method includes:
setting a data queue, wherein the data queue comprises a queue body;
dividing the queue body into a plurality of queue elements which are sequentially and continuously arranged, and sequentially recording each queue element by adopting a numerical sequence according to the time sequence of the queue element entering the queue body;
generating a production progress vernier of a producer writing data into the queue body according to the number sequence number of the queue element at the head of the queue body;
and generating a consumption progress cursor of a consumer reading data from the queue body according to the number sequence number of the queue element at the tail part of the queue body.
The method of claim 1, wherein the production progress cursor comprises a producer cursor sequence number, and wherein generating the production progress cursor for the producer writing data to the queue body according to the number sequence number of the queue element at the head of the queue body comprises:
taking the determined number sequence number of the queue element positioned at the head of the queue body as a producer cursor sequence number;
the consumption progress cursor comprises a consumer cursor serial number, and the consumption progress cursor of the consumer reading data from the queue body is generated according to the number serial number of the queue element at the tail part of the queue body, and the method comprises the following steps:
and the root takes the determined number sequence number of the queue element positioned at the tail part of the queue body as the serial number of the consumer cursor.
Optionally, the method further includes:
creating a queue memory file, wherein the queue memory file comprises the queue body and each queue element of the data queue;
and creating a vernier memory file, wherein the vernier memory file comprises a production progress vernier and a consumption progress vernier.
Optionally, the number sequence is represented by a binary unsigned integer value of a set bit.
Optionally, the data queue further includes a queue head, and the queue element includes a queue element head and a queue element body;
the queue head includes the following fields: the data queue management module is used for identifying the version number of the data queue format, the length of each queue element head, the length of each queue element body and the total number of queue elements contained in the queue body;
the queue element header includes the following fields: the actual length of the data queue, a timestamp indicating the time of generation of each of the queue elements, and a numerical sequence number of each of the queue elements.
In a second aspect, the present invention provides a method for writing data into a data queue, wherein the data queue is constructed according to the method for constructing a data structure according to any one of the above methods; the method for writing data into the data queue comprises the following steps:
initializing the data queue to obtain an initial memory buffer address of the data queue, the actual length of the data queue and a producer cursor sequence number in a production progress cursor of the data queue;
acquiring a queue element address of data to be written according to the initial memory buffer address and the producer cursor sequence number;
writing data to be written into the queue element corresponding to the queue element address;
taking the sum of the length of the written data and the actual length of the data queue as the actual length of the data queue before the data is written next time;
and increasing the producer cursor sequence number by a set value to be used as the updated producer cursor sequence number.
Optionally, obtaining the address of the queue element of the data to be written according to the initial memory buffer address and the producer cursor sequence number includes:
determining the offset address of the queue element of the data to be written according to the producer cursor sequence number;
and taking the sum of the initial memory buffer address and the offset address as the address of the queue element of the data to be written.
Optionally, the determining an offset address of a queue element to which data is to be written according to the current producer cursor sequence number includes:
determining the index of the queue element to be written with data according to the current producer cursor sequence number and the total number of queue elements contained in the queue body in the data queue;
and calculating the offset address of the queue element of the data to be written according to the length of the queue body in the data queue, the product of the index of the queue element of the data to be written and the length of the queue head in the data queue.
Optionally, the determining the index of the queue element to be written with data according to the producer cursor sequence number and the total number of queue elements included in the queue body in the data queue includes:
and taking the result obtained by performing modular operation on the total number of the queue elements contained in the queue body by the producer cursor sequence number as the index of the queue element of the data to be written.
In a third aspect, the present invention provides a method of reading data from a data queue, the data queue being constructed according to the method of constructing a data structure according to any of the methods; the method for reading data from the data queue comprises the following steps:
initializing the data queue, and acquiring an initial memory buffer address of the data queue, a producer cursor sequence number in a production progress cursor of the data queue and a consumer cursor sequence number in a consumption progress cursor;
judging whether the difference between the producer cursor serial number and the consumer cursor serial number is greater than or equal to a safety distance threshold value;
if so, adjusting the consumer cursor serial number to enable the difference between the producer cursor serial number and the adjusted consumer cursor serial number to be equal to the safety distance threshold;
if not, locally saving and updating the producer cursor sequence number;
judging whether the consumer cursor serial number is smaller than or equal to the updated producer cursor serial number or not;
if yes, not reading data from the data queue, and executing the steps of locally saving and updating the producer cursor sequence number.
Optionally, the method further includes:
when the consumer cursor sequence number is judged to be smaller than the updated producer cursor sequence number, acquiring a queue element address of data to be read according to the initial memory buffer address and the consumer cursor sequence number;
reading data from the queue element corresponding to the queue element address of the data to be read;
and increasing the serial number of the consumer cursor by a set value to be used as the updated serial number of the consumer cursor.
It can be seen from the above description that, in the above construction method, the queue elements in the data queue are recorded by the sequence numbers of the queue elements, so that the problem of index wrap-around can be avoided, the pair-out and queue-in operations on the data queue can be realized without adopting a locking mechanism, a lock-free data structure is realized, the data processing speed is high, and the computer performance can be improved. Moreover, because no locking mechanism is needed, the consumer thread and the producer thread can be different threads in the same process or threads in different processes. The method can realize multi-thread or multi-process parallel processing, and can be suitable for the scene with higher data processing speed performance of the computer. .
Drawings
FIG. 1 is a flow diagram illustrating a method for lockless data structure construction according to an exemplary embodiment of the present application;
FIG. 2 is a diagram illustrating a data structure of a data queue according to an exemplary embodiment of the present application
FIG. 3 is a flow chart illustrating a method for writing data to a data queue according to an exemplary embodiment of the present application;
FIG. 4 is a flow chart diagram illustrating a method of reading data from a data queue according to an exemplary embodiment of the present application;
fig. 5 is a schematic diagram illustrating a hardware architecture of a computer device according to an exemplary embodiment of the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
A data structure is a way to store and organize data used in a computer, and a data Queue (Queue) is a commonly used data structure.
A data queue operates on the principle of "first in first out", data being written into the queue from one end, which may be referred to as "enqueuing", and data being read from the other end, and data being dequeued from the queue, which may be referred to as "dequeuing", i.e. the element of the most first in queue is also the element of the most first out queue. The data queue can improve the problem of thread stop or dormancy caused by concurrent operation to a certain extent, and improve the data processing speed.
The data queue has two implementation modes at the data structure level:
(1) data queue based on linked list
The data queue based on the linked list is represented by the linked list, a head node and a tail node of the linked list are recorded through a head pointer and a tail pointer, a producer writes data into the queue (enqueues), namely adds a new node to the head of the linked list, and a consumer reads data from the queue (dequeues) and namely takes out (deletes) the node from the tail of the linked list. The above operations may be reversed, with the producer writing data to the queue from the tail of the linked list and the consumer reading data from the head of the linked list.
Because head and tail pointers need to be modified for enqueuing/dequeuing, when a plurality of concurrent access read-write requests exist, a data queue needs to be protected through a locking mechanism, a lightweight atomic locking mechanism cannot be used generally, a heavyweight critical area or semaphore and other locking mechanisms need to be used, a heavier locking mechanism is adopted to be not beneficial to improving the data processing speed, and under the scene that the data processing speed performance of a computer is higher, the data queue based on a linked list is not used generally.
(2) Array-based data queues.
The data queue based on the array is realized by the array, specifically, the array indexes corresponding to the head element and the tail element of the queue are respectively recorded by a head index and a tail index. The producer writes the data into the queue (enqueue), which is equivalent to writing the data to the array element pointed to by the head index; the consumer reads data from the queue (dequeues), which is equivalent to fetching data from the array element to which the tail index points.
Compared with the data queue based on the linked list, the data queue based on the array only needs to update the head index and the tail index, and a light-weight atomic lock can be used, so that the data processing speed is improved, and the performance of a computer is improved.
However, such array-based data queues have the following major problems:
(1) the problem of index wrap-around needs to be considered
When a producer writes data into a queue, the sizes of the head index and the tail index need to be compared to determine whether the queue is full. Under normal conditions, the head index is greater than or equal to the tail index, which indicates that the queue is not full, data can be written into the queue, when the index wraps around, the head index is smaller than the tail index, and at the moment, more complex conditions are needed to judge whether the queue is full, so that the data processing efficiency is influenced.
(2) The operation on the data elements in the queue through the head index and the tail index is based on the address of the atomic variable, so that the operation can be only used among a plurality of threads in a single process and cannot be used among different processes, and therefore, the operation is not suitable for multiple processes.
Aiming at the problems of the data queue, the invention provides a lock-free data queue construction method, which can realize the lock-free data queue, not only can improve the data processing speed, but also does not have the problem of index wrap-around, and can be suitable for multiple processes.
Fig. 1 is a flowchart illustrating a method for constructing a lock-free data structure according to an exemplary embodiment of the present application, and referring to fig. 1, the method includes:
step 100, setting a data queue, wherein the data queue comprises a queue body.
In this step, the data queue is also operated based on the principle of first-in first-out, and data is written into the queue from one end and read from the other end. The data structure of the data queue comprises a queue body and can also comprise a queue head.
Step 110, dividing the queue body into a plurality of queue elements which are sequentially and continuously arranged, and sequentially recording each queue element by adopting a number sequence according to the time sequence of the queue element entering the queue body, wherein each queue element comprises a queue element head and a queue element body.
In this step, the queue body includes a plurality of queue elements, and a number sequence (hereinafter, the number sequence is referred to as a sequence number for short, and is denoted by SEQ) is set for the queue elements based on the time sequence of the queue elements entering the queue body. In computer technology, machine language usually adopts binary counting, so the number sequence number of a queue element is represented by binary, for example, and the sequence number SEQ is an unsigned integer number, the number of the binary sequence number is an exponential multiple of 2, for example, 64 bits or 128 bits, etc., of course, the number sequence number can be represented by other forms of numbers, and this embodiment is not limited thereto.
For the sequence number SEQ of the record queue element, the sequence number SEQ of the first entry queue element is, for example, 0, and then the sequence numbers of the queue elements enqueued are sequentially incremented by 1. If a 64-bit binary representation of the sequence number SEQ is used, the maximum value of the sequence number SEQ is 18446744073709551615(1844 billion), and taking the maximum frequency of the CPU of the computer at present as 4GHz calculation as an example, the CPU consumes one sequence number per clock cycle of operation (the CPU consumes at least one or more clock cycles per instruction execution), the sequence numbers of the queue elements in the data queue are sufficient to be used for 42 billion seconds continuously for about 136 years, which can be regarded as infinite sequence numbers in the life cycle of the computer program running the method.
Because the data queue adopts the principle of first-in first-out, when a producer writes data into the data queue, namely queue elements enter a queue body (enqueue), the queue elements enter the queue body from the head of the queue body, and when a consumer reads data from the data queue, namely queue elements leave the queue body (out-pair), the queue elements leave the queue body from the tail of the queue body. With continuous dequeuing or enqueuing, the sequence numbers of the queue elements at the head of the queue body and the sequence numbers of the queue elements at the tail of the queue body are sequentially incremented, for example, sequentially incremented by 1.
The time of the queue element at the head of the queue body entering the queue body is earlier than the time of the queue element at the tail of the queue body entering the queue body, so the sequence number of the queue element at the head of the queue body is larger than that of the queue element at the tail of the queue body, and the sequence number of the queue element has enough growth space, thereby avoiding the index wrap-around problem.
Step 120, generating a production progress cursor of a producer writing data into the data queue according to the number sequence number of the queue element positioned at the head of the queue body;
and step 130, generating a consumption progress cursor of a consumer reading data from the data queue according to the number sequence number of the queue element positioned at the tail part of the queue body.
In the above two steps, the concept of a Cursor (denoted as Cursor) is introduced, including a production progress Cursor and a consumption progress Cursor, where a producer is a logical executor that writes data to a queue body (i.e., puts a queue element to the queue body), and can logically execute in one thread, which is called a producer thread. A consumer is a logical executor that reads data from (i.e., fetches queue elements from) a queue body, logically executable in one thread, referred to as a consumer thread.
And a production progress cursor (marked as Producer Corsur) for recording the production progress of the Producer. And a consumption progress cursor (marked as Consumer Corsur) for recording the consumption progress of the Consumer.
The production progress cursor may include, but is not limited to, the following elements: the producer cursor sequence number is the sequence number of the queue element entering the queue body next time, and can be the sequence number of the queue element at the head of the queue; and the producer cursor timestamp is used for describing the updating time of the producer cursor serial number.
The consumption progress cursor may include, but is not limited to, the following elements: the consumer cursor sequence number, which is the sequence number of the queue element leaving the queue body next time, can be the sequence number of the queue element at the tail of the queue; and the consumer cursor timestamp is used for describing the updating time of the consumer cursor sequence number.
The cursors (including the production progress cursor and the consumption progress cursor) are actually a memory buffer (buffer), and if the data queue is used for thread communication in the same process, the memory buffer can be obtained through a basic memory allocation API, for example, by calling a malloc function in a C library or calling a new function in C + +, or the like, or can be obtained based on a system call through mmap (a method for mapping a memory file).
For the sequence number of the queue element at the head of the queue, the queue element enters the queue body from the head of the queue body, for the sequence number of the queue element entering the queue body for the first time, for example, 0, and the sequence numbers of the queue elements enqueued after that are sequentially incremented by 1, so that as the queue element enters the queue body, the sequence number of the queue element at the head of the queue can be obtained.
For the sequence number of the queue element at the tail of the queue, since the length of the queue body is fixed, that is, the distance between the queue element at the tail of the queue body and the queue element at the head of the queue body is determinable, the sequence number of the queue element at the tail of the queue body can be calculated according to the difference between the sequence number of the queue element at the head of the queue body and the length of the queue body, for example, the sequence number of the queue element at the head of the queue body is M, the length of the queue body is N, and the sequence number of the queue element at the tail of the queue body is M-N.
The production progress of the producer, namely the position of the queue element entering the queue body next time and the position of the queue element leaving the queue body next time, can be obtained through the production progress cursor and the consumption progress cursor.
According to the existing data queue based on the array or the data queue based on the linked list, when a producer produces data, namely data is enqueued, whether the data queue is full needs to be judged at first, if the data queue is full, a consumer needs to wait for consuming the data, namely dequeuing the data, otherwise, the data enqueue covers the data which is enqueued at the earliest time.
When a consumer consumes data, namely data is dequeued, whether a data queue is empty needs to be judged, if the data queue is empty, the producer needs to wait for producing the data, namely the data is enqueued, otherwise, the consumer can obtain invalid data.
The reasons for the above problems are: the production speed of a producer is higher than the consumption speed of a consumer, the producer must pay attention to the consumption progress of the consumer, the consumer must pay attention to the production progress of the producer, and at the moment, a head index or a tail index must be managed through a locking mechanism so as to avoid overwriting old data when the data is enqueued or taking invalid data when the data is dequeued.
Theoretically, a scenario in which the production speed of the producer is greater than the consumption speed of the consumer must occur. For this reason, the conventional idea is to solve this problem by suppressing the production speed (rhythm) of the producer. When the production speed is higher than the consumption speed, the data queue is gradually filled, and at the moment, the producer waits for consumption of the consumer, and the producer can not continuously write data into the data queue until the data queue is in a non-full state. However, if the producer's data source is continuously producing data at the same time, the producer can only actively discard a portion of the data before enqueuing.
If we change one idea: when the data queue is full (or close to full), the consumer is enabled to actively discard the data, and the producer does not need to care whether the data queue is full or not, and does not need to care about the consumption progress of the consumer, so that the producer does not need to lock the data queue. The consumer can directly read the production progress of the producer, and only the consumption progress of the consumer is ensured to be less than or equal to (not greater than) the read production progress of the producer. Therefore, the producer does not need to pay attention to the consumer, the consumer only needs to read the production progress of the producer, attention is changed from two-way to one-way, and the producer and the consumer do not need to lock the queue.
According to the technical scheme, the production progress vernier and the consumption progress vernier are arranged, a consumer can know the production progress of the producer only by reading the production progress vernier, the producer only needs to continuously produce data according to the data production speed (rhythm) of the producer and write the data into the data queue, the consumption progress of the consumer does not need to be concerned, namely, any consumer vernier does not need to be read, and the situation that the data queue is not locked can be realized.
As can be seen from the above description, in the scheme of this embodiment, the queue elements in the data queue are recorded by the sequence numbers of the queue elements, so that the problem of index wrap-around can be avoided, the pair-out and queue-in operations on the data queue can be realized without using a locking mechanism, a lock-free data structure is realized, the data processing speed is high, and the computer performance can be improved. Moreover, because no locking mechanism is needed, the consumer thread and the producer thread can be different threads in the same process or threads in different processes. The method can realize multi-thread parallel processing and is suitable for the scene with higher data processing speed performance of the computer.
In some examples, the data queue may include a queue head in addition to the queue body, and the queue element may include a queue element head and a queue element body;
the queue head includes the following fields: the version number used for marking the data queue format, the length of each queue element head, the length of each queue element body and the total number of queue elements contained in the queue body;
the queue element header includes the following fields: the actual length of the data queue, a timestamp indicating the time at which each queue element was generated, and the numerical sequence number of each queue element.
Referring to fig. 2, the data structure of the data queue provided in this embodiment is specifically described, and as shown in fig. 2, the data queue includes a queue head and a queue body, and the queue body includes N queue elements, for example, queue element 1, queue element 2, queue element 3, queue element 4, …, and queue element N; each queue element includes a queue element head and a queue element body.
The queue head may include, but is not limited to, the following fields:
(1) a version number for identifying a data queue format;
(2) the time stamp is used for describing the generation time of the queue body;
(3) the length of the queue Element head is generally the same as that of each queue Element head, and therefore, the length of the queue Element head can represent the length of each queue Element head and can be represented as Element Header Size;
(4) the length of the queue Element Body is generally the same as that of each queue Element, so the Size of the queue Element Body can represent the length of each queue Element Body, and the length is the maximum value of the queue Element Body and can be represented as Size Element Body Max;
(5) the queue body contains the total number of queue elements, which may also be referred to as the length of the queue body, which may be denoted as Element Count.
The data structure describing the queue head by taking C language as an example is as follows:
Figure BDA0002013068490000111
Figure BDA0002013068490000121
the queue element header may include, but is not limited to, the following fields:
(1) the actual length of the queue body is used for describing the number of queue elements actually contained in the queue body;
(2) a timestamp describing a generation time of the queue element;
(3) a version number; a format for identifying a queue element header;
(4) the sequence number of the queue element is used for describing the numerical sequence number of the queue element.
The C language is taken as an example to describe the queue element head data structure as follows:
Figure BDA0002013068490000122
the data structure describing the queue elements by taking C language as an example is as follows:
Figure BDA0002013068490000123
the data structure describing the whole data queue by taking C language as an example is as follows:
Figure BDA0002013068490000124
the length of the queue element header refers to the size of the memory space of the computer occupied by the queue element header, and can be represented by the number of characters or bytes, for example, the length of the queue element header is 5 characters, and the length of the queue element header refers to the memory space occupied by the queue element header is 5 characters.
Similarly, the length of the queue element body refers to the size of the memory space occupied by the queue element body, the length of the queue body refers to the size of the memory space occupied by the queue body, the length of the queue head refers to the size of the memory space occupied by the queue head, and the length of the data queue refers to the size of the memory space occupied by the data queue.
In an optional embodiment, the method for constructing a lock-free data structure may further include the following steps:
step S140, creating a queue memory file, wherein the queue memory file comprises a queue head, a queue body, each queue element and a serial number thereof of the data queue;
step S150, a cursor memory file is created, and the cursor queue memory file includes a production progress cursor and a consumption progress cursor.
In order to read the information related to the data queue and the cursor last time (i.e. the latest time of last-time operation) after the program for writing data into the data queue or reading data is restarted, a queue memory file is created and a cursor memory file is created. The queue memory file comprises the queue body and the relevant information of each queue element, and the cursor queue memory file comprises the relevant information of the production progress cursor and the consumption progress cursor.
The embodiment of the invention also provides a data reading and writing method based on the data queue, wherein the data queue is constructed according to the data structure construction method of any one of the embodiments; as shown in fig. 3, the data reading and writing method includes:
step 200, initializing the data queue, and acquiring an initial memory buffer address of the data queue, an actual length of the data queue, and a producer cursor sequence number in a production progress cursor of the data queue.
Before performing the read/write process on the data queue, the data queue may be initialized by first performing an algorithm for initializing the data queue, and the initialization of the data queue may be completed by a separate queue initialization program, which may include the following processes:
firstly, initializing a queue memory, specifically comprising the following steps:
determining whether a queue memory file exists;
if the data queue does not exist, a queue memory file is created according to the relevant parameters of the data queue, where the queue memory file includes relevant information of the data queue, such as an initial memory buffer address of the data queue and an actual length of the data queue, and of course, may also include other information of the data queue described above, such as a queue head, a queue body, and queue elements (a queue element head and a queue element body).
If the queue memory file already exists, the required related information, such as the initial memory buffer address of the data queue and the actual length of the data queue, can be directly acquired from the queue memory file.
Secondly, initializing the cursor memory, specifically comprising the following steps:
determining whether a cursor backup file exists;
if the file exists, initializing a cursor memory file by using the cursor backup file (for example, using the copied cursor backup file as the cursor memory file);
if not, further checking whether a cursor memory file exists, if not, creating the cursor memory file, initializing the producer cursor sequence number of the production progress cursor to 0, otherwise, directly reading the producer cursor sequence number in the cursor memory file, and further reading the consumer cursor sequence number.
Specifically, the vernier Memory File may include a Producer vernier Memory File and a consumer vernier Memory File, and there is usually only one production progress vernier, and the corresponding Producer vernier Memory File may be recorded as a Producer Memory File. The consumption progress cursors can be one or more, the corresponding Memory File of the Consumer cursors can be marked as Consumer Memory File-X, and X represents the second Consumer.
For example, the mmap system may call to open the Queue memory file and the producer vernier memory file in a read-write mode to obtain a Queue memory buffer (i.e., Address of Queue) and a producer vernier memory buffer, and further obtain an initial memory buffer Address and a producer vernier sequence number of the data Queue.
Step S210, acquiring a queue element address of data to be written according to the initial memory buffer address and the producer cursor sequence number;
step S220, writing the data to be written into the queue element corresponding to the queue element address.
In the two steps, firstly, the queue element address of the data to be written is determined according to the initial memory buffer address and the current producer cursor sequence number, and then the data to be written is written into the queue element corresponding to the queue element address, so that the data writing is completed.
And step S230, taking the sum of the length of the written data and the actual length of the data queue as the actual length of the data queue before the data is written next time.
The actual length of the data queue is the total length of the part of queue elements into which data has been written, and the actual length of the data queue changes every time new data is written into the data queue, so that the actual length of the data queue is updated after data is written each time, and the updated actual length of the data queue is used as the actual length of the data queue before data is written next time, where the updated actual length of the data queue is, for example, the actual length of a queue body, and the update may specifically be the actual length of the queue body in the head of an element of the update queue.
Step S240, the producer cursor serial number is added with the set value and then is used as the updated producer cursor serial number.
In this step, the producer's cursor sequence number is further updated, each time the data to be written is written into the data queue, a new queue element enters the head of the queue body, and the corresponding producer's cursor sequence number is sequentially incremented, for example, by 1, so that the updated producer's cursor sequence number can be obtained. Of course, the number of the setting values added by the data producer cursor number every time the data producer is written may be other numbers, and is not limited to the setting value of 1.
In this embodiment, a process of writing data into the data queue, that is, an execution process of a producer algorithm, is described, and the above steps may be cyclically executed to cyclically write data into the data queue in turn.
In an optional implementation manner, the obtaining the address of the queue element to be written in the data according to the initial memory buffer address and the producer cursor sequence number in step S210 may include the following steps:
step S211, determining the offset address of the queue element of the data to be written according to the cursor sequence number of the producer;
in step S212, the sum of the initial memory buffer address and the offset address is used as the queue element address of the data to be written.
The determining the offset address of the queue element to be written with data according to the producer cursor sequence number in step S211 may specifically include:
s2110, determining the index of the queue element to be written with data according to the serial number of the cursor of the producer and the total number of the queue elements contained in the queue body in the data queue;
assuming that the total number of queue elements is N, i.e. the length of the queue body, and the sequence number of the queue element is denoted as SEQ, the INDEX of the queue element can be calculated according to the following formula one:
the formula I is as follows: INDEX ═ SEQ% N.
In the above formula one,% represents the operation of taking the modulus, then the INDEX of the queue element can be obtained by taking the modulus of SEQ to N.
As can be seen from the description of the foregoing embodiment, the producer cursor sequence number is the sequence number of the queue element located at the head of the queue body, and the index of the queue element to which data is to be written can be calculated according to the first formula, that is, the current producer cursor sequence number performs a modulo operation on the total number of the queue elements included in the queue body, and the obtained result can be used as the index of the queue element to which data is to be written.
S2111, calculating the offset address of the queue element of the data to be written according to the length of the queue body in the data queue, the product of the index of the queue element of the data to be written and the length of the queue head in the data queue.
Specifically, the offset address of the queue element to which data is to be written may be an offset address of the queue element relative to the head of the queue body, and the following describes a process of determining the offset address of the queue element to which data is to be written with a specific example, and specifically, with reference to the data structure of the data queue shown in fig. 2:
the data queue includes: a Queue head (denoted as Queue Header) and a Queue Body (denoted as Queue Body). The Queue head is of fixed length, and the Size is recorded as Size of Queue head; the queue body is of a fixed length, is composed of N consecutive queue elements, and can be understood as a queue element array, where N is the total data of the queue elements included in the queue body, and may be referred to as the number of the queue elements or the length of the queue body.
The queue element is composed of a queue element head and a queue element body. The queue Element head is of fixed length and the Size is recorded as Size of Element Header. The queue Element Body is lengthened, and the maximum value is marked as Size of Element Body. The maximum value of the queue Element is marked as Size of Element, and the length of the queue Element can be calculated by the following formula two:
the formula II is as follows: size of Element Header + Size of Element Body;
the length Size of the data Queue of Queue can be calculated according to the following formula three:
the formula III is as follows: size of Queue Header + Size of Element N;
the offset length of the queue Element relative to the head of the queue body is recorded as Off set of Element, and the offset length can be determined through the sequence number of the queue Element based on the following formula four:
the formula four is as follows: offset of Element of Size of Queue Header + Size of Element INDEX.
Assuming that the Address of the initial memory buffer of the data Queue is Address of Queue, the Queue Element Address (denoted as Address of Element) can be calculated according to the following formula five:
the formula five is as follows: address of Element of Queue + Offset of Element;
based on the above formula, after determining the sequence number of the queue element to which data is to be written (i.e., the producer cursor sequence number) and the initial memory buffer address, the address of the queue element to which data is to be written can be determined.
An embodiment of the present invention further provides a method for reading data from a data queue, as shown in fig. 4, the method specifically includes the steps of:
step S300, initializing a data queue, and acquiring an initial memory buffer address of the data queue, a producer cursor sequence number in a production progress cursor of the data queue and a consumer cursor sequence number in a consumption progress cursor;
before reading data from the data queue, initializing the data queue by using an algorithm for initializing the data queue, and ensuring that a queue memory file, a producer vernier memory file and a consumer vernier memory file exist.
Specifically, the vernier Memory File may include a Producer vernier Memory File and a consumer vernier Memory File, and the production progress vernier is usually only one, and the corresponding Producer shared Memory File may be recorded as a Producer Memory File. The consumption progress cursors can be one or more, the corresponding Memory File of the Consumer cursors can be marked as Consumer Memory File-X, and X represents the second Consumer.
Specifically, the Queue memory file and the producer vernier memory file can be opened in a read-only mode through mmap system call, so that the memory buffer (i.e., Address of Queue) and the producer vernier memory buffer of the data Queue are obtained, and then the initial memory buffer Address and the producer vernier serial number of the data Queue are obtained.
The memory file of the consumer cursor can be opened in a read-write mode through mmap system calling to obtain the buffer of the memory of the consumer cursor, and then the serial number of the consumer cursor is obtained.
Step S301, judging whether the difference between the producer cursor serial number and the consumer cursor serial number is greater than or equal to a safety distance threshold value;
step S302, if yes, the serial number of the consumer cursor is adjusted, so that the difference between the serial number of the producer cursor and the serial number of the adjusted consumer cursor is equal to the safety distance threshold.
In the above two steps, firstly, it is determined whether the difference between the producer's cursor serial number and the consumer's cursor serial number is greater than or equal to the safety distance threshold, because: in order to avoid this situation, in this embodiment, a method of adjusting the consumer cursor sequence number is adopted, that is, the consumer actively discards part of the data, and discards part of the queue elements near the tail of the queue body in the queue body of the current data queue, so that the consumer cursor sequence number actively approaches the head of the queue body, the consumer cursor sequence number increases, a difference between the producer cursor sequence number and the increased consumer cursor sequence number is equal to a safety distance threshold, and the queue is ensured not to be full by the way that the consumer actively discards part of the data.
The safety distance threshold here may be a value that is suitably smaller than the length of the queue body, for example 3/4 for the length of the queue body.
Step S303, if not, the serial number of the cursor of the producer is locally saved and updated;
step S304, judging whether the serial number of the consumer cursor is less than or equal to the serial number of the producer cursor;
step S305, if yes, not reading the data from the data queue, and performing the step 303;
step S306, if the value is less than the preset value, acquiring a queue element address of data to be read according to the initial memory buffer address and the consumer cursor sequence number;
and according to the current consumer cursor sequence number, obtaining a corresponding queue element address Address of the formula V, and converting the queue element address Address into a queue element data structure.
Step S307, reading data from the queue element corresponding to the queue element address of the data to be read.
When the difference between the producer cursor sequence number and the consumer cursor sequence number is within the safety distance threshold, the consumer can read data from the data queue, the producer cursor sequence number can be increased along with the subsequent data writing of the producer to the data queue, at the moment, the consumer thread can locally store and update the producer cursor sequence number, namely, the consumer can further locally create a copy of the producer cursor sequence number as a local variable, and the updated producer cursor sequence number can be directly read from the local subsequently.
Then, the consumer cursor serial number is further compared with the producer cursor serial number, when the consumer cursor serial number is equal to the producer cursor serial number, it indicates that there is no new data, the consumer does not read the data, the step 303 is executed, and subsequently, as the producer writes the data into the data queue, the producer cursor serial number is increased, when the consumer cursor serial number is smaller than the producer cursor serial number, it indicates that there is new data to read, and then, the data is read from the data queue.
When data is read from the data queue, firstly, the queue element address of the data to be read is determined according to the initial memory buffer address and the current consumer cursor sequence number, and then the data is read from the queue element corresponding to the queue element address, so that the data reading is completed, and the read data can be processed as required.
Step S308, the serial number of the consumer cursor is added with a set value to be used as the updated serial number of the consumer cursor.
In this step, the consumer's cursor sequence number is further updated, each time data is read from the data queue, the queue element at the tail of the queue body leaves the queue body, and the corresponding consumer's cursor sequence number is sequentially incremented, for example, by 1, so that the updated consumer's cursor sequence number can be obtained. Of course, the number of the setting values added by the serial number of the consumer cursor every time the data is read can be other numbers, and is not limited to the setting value of 1.
The data reading method of this embodiment describes a process of reading data from the data queue, that is, an execution process of the consumer algorithm, and the above steps may be executed in a loop, and data is read from the data queue in turn in a loop. If there are multiple consumers, the process of reading data by each consumer is the same, and is not described herein again.
As can be seen from the above description of the reading method and the writing method of the data queue, embodiments of the present invention
The method has the following beneficial effects:
(1) by introducing the sequence number concept of the queue elements with 'infinite space', the producer cursor sequence number and the consumer cursor sequence number are increased monotonously, the rewinding operation is not required to be carried out according to the length of the queue body, a locking mechanism is not required to be adopted, the data queue is a real non-locking data queue, and the operation complexity of the data can be reduced.
(2) The data queue without locking can be used across processes, so that the data queue can be conveniently split into a plurality of processes to be executed according to functions to be executed by a computer, logic decoupling is carried out, and the other party is not influenced by the collapse of a producer process or a consumer process.
(3) The producer can continuously produce data according to the data production speed/rhythm of the producer and write the data into the queue without paying attention to the consumption progress of the consumer (without reading any cursor information of the consumer). Here is the key to true lock-free.
(4) The consumer only needs to pay attention to the production progress (the cursor serial number of the producer needs to be read), and when the consumption progress of the consumer is far behind the production progress of the producer (the difference between the cursor serial numbers is larger than the safety distance threshold), the consumer actively discards a part of data, so that the key of truly realizing the lock-free data queue is realized.
(5) If we consider the data queue as an endless data stream, then the consumer is always chasing the producer, the producer slows down a bit, and the consumer can chase the producer (but not exceed); the producer is faster, and when the consumer falls behind, the consumer actively discards a part of data, so that a balance is kept between the producer and the consumer.
(6) By introducing the concept of producer vernier and consumer vernier backup, the consistency of the production progress and the consumption progress of the data queue can be maintained after a producer or consumer program is crashed or restarted.
In an optional implementation manner, the production progress cursor and the consumption progress cursor may be further backed up, and if the production progress cursor and the consumption progress cursor last time can be read after the program for executing the producer algorithm and the program for executing the consumer algorithm are restarted, the shared memory may be used as a memory buffer for the production progress cursor and the consumption progress cursor.
Specifically, the method comprises the following processes:
before the operating system of the computer is shut down/restarted, the memory buffer of the production progress vernier and the consumption progress vernier is stored in the backup file. The above operation may be accomplished by a shutdown self-start script.
After the operating system is started, a cursor memory file is generated through the cursor backup file. This may be done by a power-on self-boot script.
By introducing the concept of backup of the production progress cursor and the consumption progress cursor, the consistency of the production or consumption progress of the data queue after the crash or restart of a producer or a consumer program can be supported.
Embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of the method according to any of the above embodiments.
The method for constructing the lock-free data structure, the method for writing data into the data queue and the method for reading data from the data queue of the embodiment can be realized by computer equipment.
Fig. 5 is a hardware architecture diagram of a computer device 500 according to an embodiment of the present invention. Referring to fig. 5, the computer apparatus includes: a machine-readable storage medium 501 and a processor 502, and may further include a non-volatile medium 503, a communication interface 504, and a bus 505; among other things, the machine-readable storage medium 501, the processor 502, the non-volatile medium 503, and the communication interface 504 communicate with each other via a bus 505. The processor 502 may perform the methods described in the embodiments above by reading and executing machine executable instructions in the machine readable storage medium 501 corresponding to control logic of a method of constructing a data structure without locking, a method of writing data to a data queue, or a method of reading data from a data queue.
A machine-readable storage medium as referred to herein may be any electronic, magnetic, optical, or other physical storage device that can contain or store information such as executable instructions, data, and the like. For example, the machine-readable storage medium may be: a RAM (random Access Memory), a volatile Memory, a non-volatile Memory, a flash Memory, a storage drive (e.g., a hard drive), any type of storage disk (e.g., an optical disk, a dvd, etc.), or similar storage medium, or a combination thereof.
The non-volatile medium may be non-volatile memory, flash memory, a storage drive (e.g., a hard drive), any type of storage disk (e.g., an optical disk, dvd, etc.), or similar non-volatile storage medium, or a combination thereof.
Further, the computer device may be a variety of electronic devices, such as a server, a mobile phone, a Personal Digital Assistant (PDA), and so forth, to name a few.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims (10)

1. A method of lockless data structure construction, the method comprising:
setting a data queue, wherein the data queue comprises a queue body;
dividing the queue body into a plurality of queue elements which are sequentially and continuously arranged, and sequentially recording each queue element by adopting a numerical sequence according to the time sequence of the queue element entering the queue body;
generating a production progress vernier of a producer writing data into the queue body according to the number sequence number of the queue element at the head of the queue body; the production progress vernier comprises a producer vernier serial number, and the determined number serial number of the queue element positioned at the head of the queue body is used as the producer vernier serial number;
generating a consumption progress vernier of a consumer reading data from the queue body according to the number sequence number of the queue element at the tail of the queue body; the consumption progress cursor comprises a consumer cursor serial number, and the determined number serial number of the queue element positioned at the tail part of the queue body is used as the consumer cursor serial number;
when the difference between the producer cursor serial number and the consumer cursor serial number is greater than or equal to a safety distance threshold, adjusting the consumer cursor serial number to make the difference between the producer cursor serial number and the adjusted consumer cursor serial number equal to the safety distance threshold.
2. The method of claim 1, further comprising:
creating a queue memory file, wherein the queue memory file comprises the queue body and each queue element of the data queue;
and creating a vernier memory file, wherein the vernier memory file comprises a production progress vernier and a consumption progress vernier.
3. The method according to any of claims 1-2, wherein the numerical sequence number is represented by a binary unsigned integer value of a set bit.
4. The method according to any one of claims 1-2, wherein the data queue further comprises a queue head and a queue body, the queue body is a queue element sequence, and the queue element comprises a queue element head and a queue element body;
the queue head includes the following fields: the data queue management module is used for identifying the version number of the data queue format, the length of each queue element head, the length of each queue element body and the total number of queue elements contained in the queue body;
the queue element header includes the following fields: the actual length of the data queue, a timestamp indicating the time of generation of each of the queue elements, and a numerical sequence number of each of the queue elements.
5. A method of writing data to a data queue, wherein the data queue is a data queue constructed according to the method of constructing a data structure according to any one of claims 1 to 4; the method for writing data into the data queue comprises the following steps:
initializing the data queue to obtain an initial memory buffer address of the data queue, the actual length of the data queue and a producer cursor sequence number in a production progress cursor of the data queue;
acquiring a queue element address of data to be written according to the initial memory buffer address and the producer cursor sequence number;
writing data to be written into the queue element corresponding to the queue element address;
taking the sum of the length of the written data and the actual length of the data queue as the actual length of the data queue before the data is written next time;
and increasing the producer cursor sequence number by a set value to be used as the updated producer cursor sequence number.
6. The method as claimed in claim 5, wherein obtaining the queue element address of the data to be written according to the initial memory buffer address and the producer cursor sequence number comprises:
determining the offset address of the queue element of the data to be written according to the producer cursor sequence number;
and taking the sum of the initial memory buffer address and the offset address as the address of the queue element of the data to be written.
7. The method of claim 6, wherein determining an offset address of a queue element to which data is to be written based on the producer cursor sequence number comprises:
determining the index of the queue element to be written with data according to the producer cursor sequence number and the total number of queue elements contained in the queue body in the data queue;
and calculating the offset address of the queue element of the data to be written according to the product of the length of the queue element in the data queue and the index of the queue element of the data to be written and the length of a queue head in the data queue.
8. The method of claim 7, wherein determining an index of a queue element to which data is to be written based on the producer cursor sequence number and a total number of queue elements contained in a queue body in the data queue comprises:
and taking the result obtained by performing modular operation on the total number of the queue elements contained in the queue body by the producer cursor sequence number as the index of the queue element of the data to be written.
9. A method of reading data from a data queue, wherein the data queue is a data queue constructed according to the method of constructing a data structure according to any one of claims 1 to 4; the method for reading data from the data queue comprises the following steps:
initializing the data queue, and acquiring an initial memory buffer address of the data queue, a producer cursor sequence number in a production progress cursor of the data queue and a consumer cursor sequence number in a consumption progress cursor;
judging whether the difference between the producer cursor serial number and the consumer cursor serial number is greater than or equal to a safety distance threshold value;
if so, adjusting the consumer cursor serial number to enable the difference between the producer cursor serial number and the adjusted consumer cursor serial number to be equal to the safety distance threshold;
if not, the consumer locally saves and updates the producer cursor sequence number;
judging whether the consumer cursor serial number is smaller than or equal to the updated producer cursor serial number or not;
if yes, not reading data from the data queue, and executing the steps of locally saving and updating the producer cursor sequence number.
10. The method of claim 9, further comprising:
when the consumer cursor sequence number is judged to be smaller than the updated producer cursor sequence number, acquiring a queue element address of data to be read according to the initial memory buffer address and the consumer cursor sequence number;
reading data from the queue element corresponding to the queue element address of the data to be read;
and increasing the serial number of the consumer cursor by a set value to be used as the updated serial number of the consumer cursor.
CN201910253786.0A 2019-03-30 2019-03-30 Lock-free data structure construction method and data writing and reading methods Active CN110134439B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910253786.0A CN110134439B (en) 2019-03-30 2019-03-30 Lock-free data structure construction method and data writing and reading methods

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910253786.0A CN110134439B (en) 2019-03-30 2019-03-30 Lock-free data structure construction method and data writing and reading methods

Publications (2)

Publication Number Publication Date
CN110134439A CN110134439A (en) 2019-08-16
CN110134439B true CN110134439B (en) 2021-09-28

Family

ID=67568999

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910253786.0A Active CN110134439B (en) 2019-03-30 2019-03-30 Lock-free data structure construction method and data writing and reading methods

Country Status (1)

Country Link
CN (1) CN110134439B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110888727B (en) * 2019-11-26 2022-07-22 北京达佳互联信息技术有限公司 Method, device and storage medium for realizing concurrent lock-free queue
CN111143236A (en) * 2019-12-07 2020-05-12 杭州安恒信息技术股份有限公司 Memory mapping implementation queue and data reading and writing method thereof
CN111552575B (en) * 2019-12-31 2023-09-12 远景智能国际私人投资有限公司 Message consumption method, device and equipment based on message queue
CN112148488A (en) * 2020-09-22 2020-12-29 杭州电魂网络科技股份有限公司 Message processing method and system based on multi-cycle cache
CN112597249B (en) * 2020-12-26 2023-06-20 湖南快乐阳光互动娱乐传媒有限公司 Synchronous distribution storage method and system for service data
CN113176896B (en) * 2021-03-19 2022-12-13 中盈优创资讯科技有限公司 Method for randomly taking out object based on single-in single-out lock-free queue
CN113377509A (en) * 2021-06-08 2021-09-10 上海哔哩哔哩科技有限公司 Data processing method and system
CN113377295B (en) * 2021-08-13 2021-12-10 北京华云安信息技术有限公司 Data storage and reading method, device and equipment for multi-producer single-consumer
US20230153160A1 (en) * 2021-11-18 2023-05-18 International Business Machines Corporation Lock-free data aggregation on distributed systems

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110145835A1 (en) * 2009-12-14 2011-06-16 Verisign, Inc. Lockless Queues
CN103391256A (en) * 2013-07-25 2013-11-13 武汉邮电科学研究院 Base station user plane data processing and optimizing method based on Linux system
CN104639596A (en) * 2013-11-08 2015-05-20 塔塔咨询服务有限公司 System and method for multiple sender support in low latency fifo messaging using rdma
CN104954351A (en) * 2014-05-23 2015-09-30 腾讯科技(深圳)有限公司 Data detection method and apparatus
CN105868031A (en) * 2016-03-24 2016-08-17 车智互联(北京)科技有限公司 A data transmission device and method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110145835A1 (en) * 2009-12-14 2011-06-16 Verisign, Inc. Lockless Queues
CN103391256A (en) * 2013-07-25 2013-11-13 武汉邮电科学研究院 Base station user plane data processing and optimizing method based on Linux system
CN104639596A (en) * 2013-11-08 2015-05-20 塔塔咨询服务有限公司 System and method for multiple sender support in low latency fifo messaging using rdma
CN104954351A (en) * 2014-05-23 2015-09-30 腾讯科技(深圳)有限公司 Data detection method and apparatus
CN105868031A (en) * 2016-03-24 2016-08-17 车智互联(北京)科技有限公司 A data transmission device and method

Also Published As

Publication number Publication date
CN110134439A (en) 2019-08-16

Similar Documents

Publication Publication Date Title
CN110134439B (en) Lock-free data structure construction method and data writing and reading methods
CA2706737C (en) A multi-reader, multi-writer lock-free ring buffer
US8458721B2 (en) System and method for implementing hierarchical queue-based locks using flat combining
US7302684B2 (en) Systems and methods for managing a run queue
US8607249B2 (en) System and method for efficient concurrent queue implementation
US6145061A (en) Method of management of a circular queue for asynchronous access
US6668291B1 (en) Non-blocking concurrent queues with direct node access by threads
EP1271314B1 (en) Sleep queue management for operating systems
US7509463B2 (en) Cell processor atomic compare and swap using dedicated synergistic processor element
US20210019203A1 (en) Method and apparatus for multithreaded data transmission in a tee system
EP2074511B1 (en) Efficient store queue architecture
WO2012082330A1 (en) Non-blocking wait-free data-parallel scheduler
US7366831B2 (en) Lock-free bounded FIFO queue mechanism
JPH0642204B2 (en) How to remove elements from a queue or stack
US20070130438A1 (en) Atomic operation involving processors with different memory transfer operation sizes
JP2006503361A (en) Data processing apparatus and method for synchronizing at least two processing means in data processing apparatus
Aboulenein et al. Hardware support for synchronization in the Scalable Coherent Interface (SCI)
WO2022199131A1 (en) Processor apparatus and instruction execution method therefor
CN115840654A (en) Message processing method, system, computing device and readable storage medium
Jayanti et al. Logarithmic-time single deleter, multiple inserter wait-free queues and stacks
US10552343B2 (en) Zero thrash cache queue manager
US7047245B2 (en) Processing system
CN113614698A (en) Handling ring buffer updates
Mishra et al. A Dynamic Multi-Threaded Queuing Mechanism for Reducing the Inter-Process Communication Latency on Multi-Core Chips
US7249230B2 (en) Queue structure with validity vector and order array

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant