CN114064301A - Data storage and reading method, device and equipment for single writer and multiple readers - Google Patents

Data storage and reading method, device and equipment for single writer and multiple readers Download PDF

Info

Publication number
CN114064301A
CN114064301A CN202111415550.6A CN202111415550A CN114064301A CN 114064301 A CN114064301 A CN 114064301A CN 202111415550 A CN202111415550 A CN 202111415550A CN 114064301 A CN114064301 A CN 114064301A
Authority
CN
China
Prior art keywords
value
reading
data
variable
read
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.)
Pending
Application number
CN202111415550.6A
Other languages
Chinese (zh)
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 Huayuan Information Technology Co Ltd
Original Assignee
Beijing Huayuan Information 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 Huayuan Information Technology Co Ltd filed Critical Beijing Huayuan Information Technology Co Ltd
Priority to CN202111415550.6A priority Critical patent/CN114064301A/en
Publication of CN114064301A publication Critical patent/CN114064301A/en
Pending legal-status Critical Current

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/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms
    • 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/52Indexing scheme relating to G06F9/52
    • G06F2209/521Atomic

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mram Or Spin Memory Techniques (AREA)

Abstract

The embodiment of the disclosure provides a method, a device and equipment for storing and reading data by a single writer and multiple readers. The method comprises the following steps: the reading thread acquires the value of the reading position atom variable and the value of the reading position variable in the array; setting a reading mark variable, wherein the value of the reading mark variable is the value of a reading position atom variable; increasing the value of the reading position atom variable by the size of preset data to be read; if the value of the reading mark variable is the same as the value of the data reading position variable in the array, reading the data to be read from the array based on the position pointed by the data reading position variable; and if not, other reader threads are reading, the data to be read are not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable with the increased numerical value. In this way, the problem of data contention among multiple read processes in the shared memory scheme can be solved without locking.

Description

Data storage and reading method, device and equipment for single writer and multiple readers
Technical Field
The disclosure relates to the field of data storage and reading, and particularly provides a method, a device and equipment for storing and reading data by a single writer and multiple readers.
Background
Modern computers are mostly provided with a plurality of cores, software developed for the computers can use a multithread mode to develop the software in order to effectively utilize the plurality of cores, and a shared memory can meet the requirement of exchanging data among threads.
However, the scheme of sharing the memory has a problem of data contention, and how to solve the data contention is the key to improve the efficiency of the scheme. A common approach to resolving data contention is locking, but the locking operation may take up part of the performance overhead.
Disclosure of Invention
The disclosure provides a data storage and reading method, device and equipment with a single writer and multiple readers.
According to a first aspect of the present disclosure, a single writer multi-reader data storage and reading method is provided. The method comprises the following steps:
the reading thread acquires the value of the reading position atom variable and the value of the reading position variable in the array;
setting a reading mark variable, wherein the value of the reading mark variable is the value of a reading position atom variable;
increasing the value of the reading position atom variable by the size of preset data to be read;
if the value of the reading mark variable is the same as the value of the data reading position variable in the array, reading the data to be read from the array based on the position pointed by the data reading position variable;
and if the value of the reading mark variable is different from the value of the data reading position variable in the array, other reader threads are reading, the data to be read is not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable after the numerical value is increased.
In some implementations of the first aspect, reading preset data to be read from the array based on a position pointed by the data reading position variable includes:
acquiring the value of a write-in position variable in the array;
determining the residual reading space of the array according to the value of the reading position variable and the value of the writing position variable;
and if the residual reading space is larger than or equal to the space occupied by the data to be read, reading the data to be read from the array based on the position pointed by the data reading position variable.
In some implementations of the first aspect, determining a remaining read space of the array from the value of the read location variable and the value of the write location variable includes:
if the value of the writing position variable is smaller than the value of the reading position variable, the residual reading space is the sum of the capacity value of the array and the value of the writing position variable minus the value of the reading position variable;
and if the value of the writing position variable is greater than or equal to the value of the reading position variable, the residual reading space is obtained by subtracting the value of the reading position variable from the value of the writing position variable.
In some implementations of the first aspect, the data to be read is not read if the remaining read space is less than the space occupied by the data to be read.
In some implementations of the first aspect, reading preset data to be read from the array based on a position pointed by the data reading position variable, further includes:
and when the array is read to the tail element position and the data to be read is not completely read, reading the part of the data to be read, which is not read, of the array from the head element position of the array until the data with the size of the data to be read is read.
In some implementations of the first aspect, if the value of the read position variable plus the size of the data to be read is greater than the array size, the value of the read atomic position variable after the numerical value is increased minus the array size.
In some implementations of the first aspect, further comprising a write thread, comprising:
determining the size of writable data according to the value of the read position variable and the value of the write position variable;
and if the size of the writable data is larger than that of the expected writing data, writing the data stored in the array based on the position pointed by the writing position variable, and updating the value of the writing position variable, wherein the size of the expected writing data is obtained by subtracting the size of the residual reading space from the size of the data to be read.
In some implementations of the first aspect, determining a size of the writable data according to the value of the read location variable and the value of the write location variable includes:
if the value of the writing position variable is smaller than the value of the reading position variable, subtracting the value of the writing position variable from the value of the reading position variable, and then subtracting one to determine the size of the writable data;
and if the value of the writing position variable is larger than the value of the reading position variable, the size of the writable data is obtained by subtracting the value of the writing position variable from the sum of the capacity value of the array and the value of the reading position variable and then subtracting one from the value of the writing position variable.
According to a second aspect of the present disclosure, there is provided a single writer multiple reader data storage and reading apparatus, the apparatus comprising:
the acquisition module is used for enabling the reading thread to acquire the value of the reading position atom variable in the array and the value of the reading position variable;
the assignment module is used for setting a reading mark variable, and the value of the reading mark variable is the value of the reading position atom variable;
the reading position atomic variable adjusting module is used for increasing the value of the reading position atomic variable by the size of preset data to be read;
the processing module is used for reading the data to be read from the array based on the position pointed by the data reading position variable if the value of the reading mark variable is the same as the value of the data reading position variable in the array; and if the value of the reading mark variable is different from the value of the data reading position variable in the array, other reader threads are reading, the data to be read is not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable after the numerical value is increased. .
According to a third aspect of the present disclosure, an electronic device is provided. The electronic device includes: a memory having a computer program stored thereon and a processor implementing the method as described above when executing the program.
According to the method and the device, whether other processes are reading data is determined according to the value of the reading mark variable and the value of the data reading position variable, so that the problem of data competition among a plurality of reading processes in a shared memory scheme is solved under the condition of no locking, further computing resources are saved, and the resource utilization rate is improved.
It should be understood that the statements herein reciting aspects are not intended to limit the critical or essential features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. The accompanying drawings are included to provide a further understanding of the present disclosure, and are not intended to limit the disclosure thereto, and the same or similar reference numerals will be used to indicate the same or similar elements, where:
FIG. 1 illustrates a flow diagram of a single writer multiple reader data storage and read method according to an embodiment of the disclosure;
FIG. 2 shows a read process schematic according to an embodiment of the present disclosure;
FIG. 3 shows a write process schematic according to an embodiment of the disclosure;
FIG. 4 illustrates a block diagram of a single writer multiple reader data storage and reading apparatus, in accordance with an embodiment of the present disclosure;
FIG. 5 illustrates a block diagram of an electronic device for implementing a single writer multiple reader data storage and reading method of an embodiment of the disclosure.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are some, but not all embodiments of the present disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
In the disclosure, whether other processes are reading data is determined according to the value of the read flag variable and the value of the data reading position variable, so that the problem of data competition in multi-thread reading in a single writer and multiple readers is solved.
FIG. 1 illustrates a flow diagram of a single writer multiple reader data storage and reading method according to an embodiment of the disclosure.
It should be noted that before the method shown in fig. 1 is executed, the used data and variables need to be initialized, specifically, the array may be defined as a, the size is n +1, the read position variable may be defined as R, the value is 0, the write position variable may be defined as W, the value is 0, the read position atom variable may be defined as aR, the value is 0, and the read flag variable may be defined as t.
Then, based on the defined array and the variable, taking reading the data of the I byte as an example, the method in fig. 1 is executed.
As shown in fig. 1, the data storage and reading method for single writer and multiple readers includes:
s101, a reading thread acquires the value of a reading position atom variable and the value of a reading position variable in an array;
s102, setting a reading mark variable, wherein the value of the reading mark variable is the value of a reading position atom variable;
s103, increasing the value of the reading position atom variable by the size of preset data to be read;
s104, if the value of the reading mark variable is the same as the value of the data reading position variable in the array, reading the data to be read from the array based on the position pointed by the data reading position variable;
and S105, if the value of the reading mark variable is different from the value of the data reading position variable in the array, other reader threads are reading, the data to be read is not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable with the increased value.
It is understood that steps S104 and S105 are selectively performed according to the comparison result of the t value and the R value.
For ease of understanding, taking as an example that each value is an initial value, two cases with and without other readers are analyzed here as follows:
when no other reader is reading, in step S101, the value of the read position atom variable aR and the value of the read position variable R are both 0;
in step S102, the value of the reading flag variable t is set to the value of the reading position atom variable aR, that is, t is 0;
in step S103, aR + I is set to aR, and it is seen that the value of aR changes;
if t is equal to R is equal to 0, step S104 is executed to continue reading, i.e., reading is started from the position of the reading position variable R.
When there is another reader reading, in step S101, R is 0, and since the aR value is changed by another reader in step S103 of another reader, the other reader reads IOthersByte data, therefore, at this time aR ═ aR + IOthers=0+IOthers=IOthers
In step S102, t ═ IOthers
In step S103, aR ═ I is performedOthers+I;
Since t is IOthersNot equal to R, therefore, it is judged that there is another reader reading, so that reading is stopped, and aR is made equal to IOthers+I-I=IOthersI.e., aR recovery.
From the above analysis, it can be seen that, as long as other readers read data from the array, the value of the reading position atomic variable changes, but the value of the reading position atomic variable in the reading process has not changed yet, so that it can be determined whether other readers are reading according to the change of the value of the atomic variable, that is, comparing the value of the reading flag variable t with the value of the reading position variable. And reading the data to be read under the condition that no other reading process reads, and not reading under the condition that the other reading process reads, namely executing S104 or S105, so as to solve the problem of data competition by no lock under the condition that a plurality of reading processes exist.
The read position variable R means that reading is started from the data position, and the read atomic position variable aR means that reading is completed at the data position.
In steps S102 and S103, the process of changing the value of the read position atom variable aR and assigning the value to the read flag variable t may be represented by t ═ atomic _ add (aR, I) -I.
In step S104, reading preset data to be read from the array based on the position indicated by the data reading position variable, including:
acquiring the value of a write-in position variable in the array;
determining the residual reading space of the array according to the value of the reading position variable and the value of the writing position variable;
and if the residual reading space is larger than or equal to the space occupied by the data to be read, reading the data to be read from the array based on the position pointed by the data reading position variable.
The remaining read space is represented by REST.
According to the embodiment of the disclosure, if the remaining reading space is greater than or equal to the space occupied by the data to be read, which indicates that the remaining reading space is sufficient to completely read the data to be read, the data to be read is read from the array based on the position indicated by the data reading position variable.
In some embodiments, determining the remaining read space of the array from the value of the read position variable and the value of the write position variable comprises:
if the value of the writing position variable is smaller than the value of the reading position variable, the residual reading space is the sum of the capacity value of the array and the value of the writing position variable minus the value of the reading position variable;
and if the value of the writing position variable is greater than or equal to the value of the reading position variable, the residual reading space is obtained by subtracting the value of the reading position variable from the value of the writing position variable.
That is, when W < R, REST is W + n +1-R, and when W ≧ R, REST is W-R.
In some embodiments, the data to be read is not read if the remaining read space is less than the space occupied by the data to be read.
It can be understood that, under the condition that the remaining read space is smaller than the space occupied by the data to be read, it indicates that the I-byte data to be read cannot be completely read, the terminal device does not read the data to be read, and needs to wait for a writer to write some data to increase the remaining read space in the array to achieve sufficient reading of the data to be read, and execute atomic _ sub (aR, I), and return to S101.
In some embodiments, reading preset data to be read from the array based on a position pointed by the data reading position variable, further includes:
and when the array is read to the tail element position and the data to be read is not completely read, reading the part of the data to be read, which is not read, of the array from the head element position of the array until the data with the size of the data to be read is read.
In order to enable reading to be circulated, the array may be a circular array, and therefore, in the process of reading preset data to be read from the array based on the position pointed by the data reading position variable R, the data to be read may be sequentially read from the position pointed by the reading position variable R of the array, and if the data to be read reaches the tail of the array, the data to be read continues to be read from the head of the array until the I-byte data is read.
And calculating tmpr-R + I, if tmpr is less than n +1, indicating that the data to be read cannot be read to the tail of the array, updating the value of R to tmpr, if tmpr is more than or equal to n +1, indicating that the data to be read can be read to the tail of the array, and updating the value of R to tmpr-n-1 so as to be used for representing the value of R in the size range of the array n + 1.
In some embodiments, if the value of the read position variable plus the size of the data to be read is greater than the array size, the value of the read atomic position variable after the numerical value is incremented is subtracted by the array size.
That is, when tmpr ≧ n +1, atomic _ sub (aR, n +1) is executed for representing the changed value of aR within the size range of the array n + 1.
In order to describe the process of data storage more clearly, in some embodiments, the processes of S101 to S105 may also be as shown in the read process diagram of fig. 2.
In some embodiments, the method shown in fig. 1 may further include a data writing process, and fig. 3 shows a schematic diagram of a writing process according to an embodiment of the disclosure.
As shown in fig. 3, the write thread includes:
determining the size of writable data according to the value of the read position variable and the value of the write position variable;
and if the size of the writable data is larger than that of the expected writing data, writing the data stored in the array based on the position pointed by the writing position variable, and updating the value of the writing position variable, wherein the size of the expected writing data is obtained by subtracting the size of the residual reading space from the size of the data to be read.
According to the embodiment of the disclosure, in the process of data writing, the write thread determines the size REST of the writable data according to the value of the read position variable R and the value of the write position variable W. And if the REST is larger than or equal to the size of the expected written data, writing the expected written data based on the position pointed by the writing position variable, and updating the value of the writing position variable R, wherein the size A of the expected written data is the size of the data to be read minus the size of the residual reading space. If REST < the size a of the desired write data, the data is not written and the start position is returned.
In some embodiments, determining the size of the writable data according to the value of the read location variable and the value of the write location variable includes:
if the value of the writing position variable is smaller than the value of the reading position variable, subtracting the value of the writing position variable from the value of the reading position variable, and then subtracting one to determine the size of the writable data;
and if the value of the writing position variable is larger than the value of the reading position variable, the size of the writable data is obtained by subtracting the value of the writing position variable from the sum of the capacity value of the array and the value of the reading position variable and then subtracting one from the value of the writing position variable.
That is, if W < R, REST ═ R-W-1; if W is not less than R, REST is n-W + R.
It should be further noted that, in some embodiments, when data of the array is written, writing is started from the W position of the array, and if the data is written to the tail of the array, writing is continued from the head of the array. And in the process of updating the value of the writing position variable, calculating tmpw to be W + A, if the tmpw is less than or equal to n, setting the value of the updated writing position variable W to be tmpw, otherwise, setting the value of the updated writing position variable W to be tmpr-n-1.
According to the method and the device, whether other processes are reading data is determined according to the value of the reading mark variable and the value of the data reading position variable, so that the problem of data competition among a plurality of reading processes in a shared memory scheme is solved under the condition of no locking, further computing resources are saved, and the resource utilization rate is improved.
It is noted that while for simplicity of explanation, the foregoing method embodiments have been described as a series of acts or combination of acts, it will be appreciated by those skilled in the art that the present disclosure is not limited by the order of acts, as some steps may, in accordance with the present disclosure, occur in other orders and concurrently. Further, those skilled in the art should also appreciate that the embodiments described in the specification are exemplary embodiments and that acts and modules referred to are not necessarily required by the disclosure.
The above is a description of embodiments of the method, and the embodiments of the apparatus are further described below.
FIG. 4 illustrates a block diagram of a single writer multiple reader data storage and reading apparatus, in accordance with an embodiment of the present disclosure. As shown in fig. 4, the apparatus 400 includes:
401, an obtaining module, configured to enable a reading thread to obtain a value of a reading position atom variable and a value of a reading position variable in an array;
402, an assignment module, configured to set a read flag variable, where a value of the read flag variable is a value of a read position atom variable;
403, a reading position atomic variable adjusting module, configured to increase a value of the reading position atomic variable by a size of preset data to be read;
404, a processing module, configured to read the data to be read from the array based on a position pointed by the data reading position variable if a value of a reading flag variable is the same as a value of the data reading position variable in the array; and if the value of the reading mark variable is different from the value of the data reading position variable in the array, other reader threads are reading, the data to be read is not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable after the numerical value is increased.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the described module may refer to the corresponding process in the foregoing method embodiment, and is not described herein again.
In the technical scheme of the disclosure, the acquisition, storage, application and the like of the personal information of the related user all accord with the regulations of related laws and regulations, and do not violate the good customs of the public order.
According to an embodiment of the present disclosure, the present disclosure also provides an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method 100 described above.
FIG. 5 shows a schematic block diagram of an electronic device 500 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
The device 500 comprises a computing unit 501 which may perform various suitable actions and processes in accordance with a computer program stored in a Read Only Memory (ROM)502 or a computer program loaded from a storage unit 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The calculation unit 501, the ROM 502, and the RAM 503 are connected to each other by a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
A number of components in the device 500 are connected to the I/O interface 505, including: an input unit 506 such as a keyboard, a mouse, or the like; an output unit 507 such as various types of displays, speakers, and the like; a storage unit 508, such as a magnetic disk, optical disk, or the like; and a communication unit 509 such as a network card, modem, wireless communication transceiver, etc. The communication unit 509 allows the device 500 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunication networks.
The computing unit 501 may be a variety of general-purpose and/or special-purpose processing components having processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The computing unit 501 performs the various methods and processes described above, such as the method 100. For example, in some embodiments, the method 100 may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 508. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device 500 via the ROM 502 and/or the communication unit 509. When loaded into RAM 503 and executed by the computing unit 501, may perform one or more of the steps of the method 100 described above. Alternatively, in other embodiments, the computing unit 501 may be configured to perform the method 100 by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server with a combined blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel, sequentially, or in different orders, as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved, and the present disclosure is not limited herein.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.

Claims (10)

1. A method for storing and reading data by a single writer and multiple readers, comprising:
the reading thread acquires the value of the reading position atom variable and the value of the reading position variable in the array;
setting a reading mark variable, wherein the value of the reading mark variable is the value of a reading position atom variable;
increasing the value of the reading position atom variable by the size of preset data to be read;
if the value of the reading mark variable is the same as the value of the data reading position variable in the array, reading the data to be read from the array based on the position pointed by the data reading position variable;
and if the value of the reading mark variable is different from the value of the data reading position variable in the array, other reader threads are reading, the data to be read is not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable after the numerical value is increased.
2. The method as claimed in claim 1, wherein reading the predetermined data to be read from the array based on the location pointed by the data reading location variable comprises:
acquiring the value of a write-in position variable in the array;
determining the residual reading space of the array according to the value of the reading position variable and the value of the writing position variable;
and if the residual reading space is larger than or equal to the space occupied by the data to be read, reading the data to be read from the array based on the position pointed by the data reading position variable.
3. The single writer multiple reader data storage and read method of claim 2 wherein determining the remaining read space of said array based on the value of said read location variable and the value of said write location variable comprises:
if the value of the writing position variable is smaller than the value of the reading position variable, the residual reading space is the sum of the capacity value of the array and the value of the writing position variable minus the value of the reading position variable;
and if the value of the writing position variable is greater than or equal to the value of the reading position variable, the residual reading space is obtained by subtracting the value of the reading position variable from the value of the writing position variable.
4. The method of claim 2, wherein the data to be read is not read if the remaining read space is less than the space occupied by the data to be read.
5. The method of claim 2, wherein the predetermined data to be read is read from the array based on the location indicated by the data read location variable, further comprising:
and when the array is read to the tail element position and the data to be read is not completely read, reading the part of the data to be read, which is not read, of the array from the head element position of the array until the data with the size of the data to be read is read.
6. The single writer multiple reader data storage and read method of claim 5,
and if the value of the reading position variable plus the size of the data to be read is larger than the size of the array, subtracting the size of the array from the value of the reading atom position variable after the numerical value is increased.
7. The single writer multiple reader data storage and read method of claim 1 further comprising a write thread comprising:
determining the size of writable data according to the value of the read position variable and the value of the write position variable;
and if the size of the writable data is larger than that of the expected writing data, writing the data stored in the array based on the position pointed by the writing position variable, and updating the value of the writing position variable, wherein the size of the expected writing data is obtained by subtracting the size of the residual reading space from the size of the data to be read.
8. The single writer multiple reader data storage and read method of claim 6 wherein determining the size of writeable data from the value of said read location variable and the value of said write location variable comprises:
if the value of the writing position variable is smaller than the value of the reading position variable, subtracting the value of the writing position variable from the value of the reading position variable, and then subtracting one to determine the size of the writable data;
and if the value of the writing position variable is larger than the value of the reading position variable, the size of the writable data is obtained by subtracting the value of the writing position variable from the sum of the capacity value of the array and the value of the reading position variable and then subtracting one from the value of the writing position variable.
9. A single writer multiple reader data storage and reading apparatus comprising:
the acquisition module is used for enabling the reading thread to acquire the value of the reading position atom variable in the array and the value of the reading position variable;
the assignment module is used for setting a reading mark variable, and the value of the reading mark variable is the value of the reading position atom variable;
the reading position atomic variable adjusting module is used for increasing the value of the reading position atomic variable by the size of preset data to be read;
the processing module is used for reading the data to be read from the array based on the position pointed by the data reading position variable if the value of the reading mark variable is the same as the value of the data reading position variable in the array; and if the value of the reading mark variable is different from the value of the data reading position variable in the array, other reader threads are reading, the data to be read is not read from the array, and the preset size of the data to be read is subtracted from the value of the reading atom position variable after the numerical value is increased.
10. An electronic device, comprising: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-8.
CN202111415550.6A 2021-11-25 2021-11-25 Data storage and reading method, device and equipment for single writer and multiple readers Pending CN114064301A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111415550.6A CN114064301A (en) 2021-11-25 2021-11-25 Data storage and reading method, device and equipment for single writer and multiple readers

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111415550.6A CN114064301A (en) 2021-11-25 2021-11-25 Data storage and reading method, device and equipment for single writer and multiple readers

Publications (1)

Publication Number Publication Date
CN114064301A true CN114064301A (en) 2022-02-18

Family

ID=80276221

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111415550.6A Pending CN114064301A (en) 2021-11-25 2021-11-25 Data storage and reading method, device and equipment for single writer and multiple readers

Country Status (1)

Country Link
CN (1) CN114064301A (en)

Similar Documents

Publication Publication Date Title
CN114327946A (en) Shared memory access control method and device, electronic equipment and automatic driving vehicle
CN113010325B (en) Method and device for realizing read-write lock and electronic equipment
CN111125057A (en) Service request processing method and device and computer system
CN112650449B (en) Method and system for releasing cache space, electronic device and storage medium
CN113377295B (en) Data storage and reading method, device and equipment for multi-producer single-consumer
CN116166583B (en) Data precision conversion method and device, DMA controller and medium
CN117236236A (en) Chip design data management method and device, electronic equipment and storage medium
CN114564149B (en) Data storage method, device, equipment and storage medium
CN114064301A (en) Data storage and reading method, device and equipment for single writer and multiple readers
CN112783574B (en) Application development method, device, equipment and storage medium
CN115904240A (en) Data processing method and device, electronic equipment and storage medium
CN115114612A (en) Access processing method, device, electronic equipment and storage medium
CN115617800A (en) Data reading method and device, electronic equipment and storage medium
CN114386577A (en) Method, apparatus, and storage medium for executing deep learning model
CN111143351B (en) IMSI data management method and equipment
CN114356589B (en) Multi-writer and multi-reader data storage and reading method, device and equipment
CN113836157A (en) Method and device for acquiring incremental data of database
CN114610575B (en) Method, apparatus, device and medium for calculating updated peak value of branch
CN113419871B (en) Object processing method based on synchronous groove and related product
CN116680080A (en) Memory management method and device, electronic equipment and storage medium
CN115390992A (en) Virtual machine creating method, device, equipment and storage medium
CN114331804A (en) Resource processing method, device, equipment and storage medium
CN116149946A (en) Data acquisition method and device, electronic equipment and storage medium
CN115202791A (en) Method and device for determining first screen loading resource, server and storage medium
CN115934256A (en) Dynamic graph execution method and device under artificial intelligence graph framework

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