WO2020177549A1 - 数据的读写方法和装置 - Google Patents

数据的读写方法和装置 Download PDF

Info

Publication number
WO2020177549A1
WO2020177549A1 PCT/CN2020/076106 CN2020076106W WO2020177549A1 WO 2020177549 A1 WO2020177549 A1 WO 2020177549A1 CN 2020076106 W CN2020076106 W CN 2020076106W WO 2020177549 A1 WO2020177549 A1 WO 2020177549A1
Authority
WO
WIPO (PCT)
Prior art keywords
storage unit
data
target storage
queue
field
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.)
Ceased
Application number
PCT/CN2020/076106
Other languages
English (en)
French (fr)
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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Publication of WO2020177549A1 publication Critical patent/WO2020177549A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the invention relates to the field of data processing, and in particular to a method and device for reading and writing data.
  • Distributed database system refers to the use of high-speed computer networks to connect multiple physically dispersed data storage units to form a logically unified database.
  • the basic idea of a distributed database is that the data in the original centralized database is scattered and stored on multiple data storage nodes connected through the network to obtain larger storage capacity and higher access volume.
  • the distributed database runs in parallel with multiple threads and cannot guarantee the running order of instructions between each thread, so the problem of out-of-order conflicts is prone to occur.
  • the embodiment of the present invention provides a method and device for reading and writing data, so as to at least solve the technical problem that the built-in blocking queue of the JDK is prone to out-of-order conflicts under the condition of high concurrency, resulting in low concurrency efficiency.
  • a method for reading and writing data including: a data writing module finds a target storage unit from a storage queue, wherein the storage queue includes a plurality of storage units, and each storage unit is at least Including: the first field used to store the element and the second field used to store the read-write identifier; the data writing module judges whether the target storage unit is empty according to the second field of the target storage unit; in the case that the target storage unit is empty Next, the data writing module writes the element to be written into the first field of the target storage unit, and changes the second field of the target storage unit to a first preset value, where the first preset value is used to indicate the target storage The cell has been written to the element.
  • a data reading module searches for a target storage unit from a storage queue, wherein the storage queue includes a plurality of storage units, and each storage unit Including: the first field used to store the element and the second field used to store the read-write identifier; the data reading module judges whether the target storage unit has been written according to the second field of the target storage unit; the target storage unit has been In the case of writing an element, the data reading module reads the element in the target storage unit and changes the second field of the target storage unit to a first preset value, where the first preset value is used to indicate the target storage unit Is empty.
  • a data reading and writing device including: a search module, used for the data writing module to find a target storage unit from a storage queue, wherein the storage queue includes a plurality of storage Unit, each storage unit includes at least: a first field for storing elements and a second field for storing read-write identifiers; a judgment module for data writing module to judge the target storage unit according to the second field of the target storage unit Whether it’s empty; the write module is used to write the element to be written into the first field of the target storage unit when the target storage unit is empty, and change the second field of the target storage unit to The first preset value, where the first preset value is used to indicate that the target storage unit has been written into the element.
  • a data reading and writing device which includes: a search module for the data reading module to search for a target storage unit from a storage queue, wherein the storage queue includes a plurality of storage units , Each storage unit includes: a first field for storing an element and a second field for storing a read-write identifier; a judgment module for the data reading module to judge whether the target storage unit has been stored according to the second field of the target storage unit Is written; the write module is used to read the element in the target storage unit and change the second field of the target storage unit to the first preset when the target storage unit has been written into the element.
  • the storage unit in the embodiment of the present invention includes a field for storing an element and a field for storing a read-write identifier.
  • the identification determines whether the cell is empty, so as to determine whether to access the storage cell to write elements to it, thereby avoiding the data reading module has not read the element from the storage cell, the data writing module accesses before the data reading module.
  • Figure 1 shows a block diagram of the hardware structure of a computer terminal (or mobile device) used to implement a method for reading and writing data;
  • FIG. 3 is a schematic diagram of a blocking queue of a distributed database according to Embodiment 1 of the present application.
  • FIG. 4 is a schematic diagram of a data writing module writing elements to a storage queue according to Embodiment 1 of the present application;
  • Figure 5 is a schematic diagram of threads with a difference of 2 ⁇ n accessing the same Hub out of order
  • FIG. 6 is a schematic diagram of a thread with a phase difference of 2 ⁇ n reading and writing data according to Embodiment 1 of the present application;
  • FIG. 7 is a flow chart of a method for reading and writing data according to Embodiment 2 of the present application.
  • FIG. 8 is a schematic diagram of a data reading module reading storage queue elements according to Embodiment 2 of the present application.
  • FIG. 9 is a schematic diagram of a data reading and writing device according to Embodiment 3 of the present application.
  • FIG. 10 is a schematic diagram of a data reading and writing device according to Embodiment 4 of the present application.
  • Fig. 11 is a structural block diagram of a computer terminal according to Embodiment 5 of the present application.
  • a queue is a common data structure.
  • a queue is a linear table with restricted operations. The end that performs the insertion operation is called the end of the queue, and the end that performs the removal operation is called the head of the queue.
  • Element The basic unit used to represent the insertion and removal operations on the queue.
  • Bounded queue Refers to a special form of queue, the length of the queue has an upper limit. When the number of elements in the queue is equal to the length of the queue, the queue is full.
  • Producer the producer in this application is used to indicate the behavior module for inserting the queue.
  • Consumers Consumers. Consumers in this application are used to represent the behavior modules for taking out the queue.
  • BlockingQueue Blocking queue, which supports blocking waiting on the basis of the queue. When the queue is empty, the consumer waits for elements in the queue before taking them out. When the queue is full, the producer waits for the queue to be not full before inserting.
  • Handler Lindorm's internal object, responsible for executing requests.
  • a Handler corresponds to a thread.
  • JDK Java Development Kit. JDK is the core of the entire Java development. It includes the JAVA operating environment (JVM+Java system class library) and JAVA tools.
  • RPC module Remote Procedure Call
  • RPC is short for remote procedure call
  • RPC module is a program module that implements remote procedure call.
  • Cacheline cache block, the smallest unit for CPU to read or write data from memory.
  • X86CPU generally Cacheline size is 64Byte.
  • LindormBlockingQueue It is a blocking queue compatible with the JDK BlockingQueue interface proposed in this application. Mainly used for Lindorm internal RPC module and Handler to temporarily store and transfer RPC requests.
  • false-sharing-padding is pseudo-sharing, which means that in the computer architecture, the cpu uses cacheline as the smallest unit to cache memory data in the cpu cache, and at the same time modify adjacent irrelevant variables. Since they may be in the same cacheline, performance degradation may result. False-sharing-padding refers to adding meaningless padding space before and after the variable to make it exclusive to a cacheline and avoid false-sharing.
  • cacheline dirty read an optimization strategy based on cpu cache. Refers to some occasions when the precise value of the shared variable in the memory does not need to be known, allowing dirty reads from the cpu cache. This strategy can speed up the operation of the program.
  • an embodiment of a method for reading and writing data is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, And, although a logical sequence is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than here.
  • FIG. 1 shows a block diagram of the hardware structure of a computer terminal (or mobile device) for implementing a method for reading and writing data.
  • the computer terminal 10 may include one or more (shown as 102a, 102b, ..., 102n in the figure) processor 102 (the processor 102 may include, but is not limited to, a micro Processor MCU or programmable logic device FPGA or other processing device), memory 104 for storing data, and transmission module for communication function.
  • the computer terminal 10 can also include: display, input/output interface (I/O interface), universal serial bus (USB) port (can be included as one of the ports of the I/O interface), network interface, power supply And/or camera.
  • I/O interface input/output interface
  • USB universal serial bus
  • FIG. 1 is only for illustration, and does not limit the structure of the above electronic device.
  • the computer terminal 10 may also include more or fewer components than those shown in FIG. 1, or have a different configuration from that shown in FIG.
  • the aforementioned one or more processors 102 and/or other data processing circuits may generally be referred to as "data processing circuits" herein.
  • the data processing circuit can be embodied in whole or in part as software, hardware, firmware or any other combination.
  • the data processing circuit may be a single independent processing module, or be fully or partially integrated into any one of the other elements in the computer terminal 10 (or mobile device).
  • the data processing circuit is used as a kind of processor control (for example, selection of a variable resistance terminal path connected to an interface).
  • the memory 104 can be used to store software programs and modules of application software, such as program instructions/data storage devices corresponding to the data reading and writing method in the embodiment of the present invention.
  • the processor 102 runs the software programs and modules stored in the memory 104, In order to perform various functional applications and data processing, that is, to achieve the above-mentioned data reading and writing method.
  • the memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
  • the memory 104 may further include a memory remotely provided with respect to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
  • the transmission device is used to receive or send data via a network.
  • the above-mentioned specific examples of the network may include a wireless network provided by the communication provider of the computer terminal 10.
  • the transmission device includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station to communicate with the Internet.
  • the transmission device may be a radio frequency (RF) module, which is used to communicate with the Internet in a wireless manner.
  • RF radio frequency
  • the display may be, for example, a touch screen liquid crystal display (LCD), which may enable a user to interact with the user interface of the computer terminal 10 (or mobile device).
  • LCD liquid crystal display
  • the computer device (or mobile device) shown in FIG. 1 may include hardware elements (including circuits) and software elements (including computer-readable media stored on a computer-readable medium). Code), or a combination of hardware and software components.
  • FIG. 1 is only an example of a specific specific example, and is intended to show the types of components that may be present in the above-mentioned computer device (or mobile device).
  • FIG. 2 is a flowchart of a method for reading and writing data according to Embodiment 1 of the present application.
  • Step S21 the data writing module finds the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, and each storage unit includes at least: a first field for storing elements and a storage The second field.
  • the aforementioned data writing module may be an RPCReader.
  • the storage queue can be a blocking queue used in a distributed database, and the queue is a bounded queue.
  • the above-mentioned read/write identifier is an identifier used to characterize the read/write status of the storage unit, and is used for the data writing module or the data reading module to determine the current read/write status of the storage unit according to the identifier.
  • the read and write status of a storage unit is used to indicate whether its status allows the element to be read or written.
  • the data writing module determines the target storage unit, which may be based on the queue rules, each time determining the next storage unit of the current storage unit as the target storage unit.
  • FIG. 3 is a schematic diagram of a blocking queue of a distributed database according to Embodiment 1 of the present application.
  • the storage queue may use an array with a length of 2 ⁇ n as Storage structure.
  • Each Hub consists of two fields: value (first field) and code (second field).
  • the value is used to store the elements written by the data write module, and the code is used to store the access control identification in the producer and consumer mode, that is, the above-mentioned read-write identification.
  • Step S23 The data writing module judges whether the target storage unit is empty according to the second field of the target storage unit.
  • the data writing module After determining the target storage unit, the data writing module reads the content in the second field of the target storage unit, and determines whether the target storage unit is empty according to the content of the second field. Still taking Hub including value and code as an example, the data writing module takes out the target Hub, reads the code field of the Hub, and determines whether the target unit is empty according to the code field of the Hub.
  • the content in the code can be A or B.
  • a code value of A indicates that the Hub is empty, and a code value of B indicates that the Hub has been written to the element. After the data writing module reads the code value of the Hub, it determines whether it is A, so that it can be determined whether the Hub is empty.
  • Step S25 when the target storage unit is empty, the data writing module writes the element to be written into the first field of the target storage unit, and changes the second field of the target storage unit to the first preset value, where , The first preset value is used to indicate that the target storage unit has been written into the element.
  • the data writing module determines that the target storage cell is empty, the element is written to the storage cell. If the target storage unit is not empty, the data writing module can determine the new target storage unit, and enter the step of determining whether the new target storage unit is empty, until an empty storage unit is found.
  • the data writing module After the data writing module writes the element to be written into the target storage unit, the state of the target storage unit has changed. Therefore, the data writing module also needs to change the read/write identifier in the second field of the target storage unit to change The status of the target storage unit.
  • the code value is A to indicate that the Hub is empty
  • the code value is B to indicate that the Hub has been written into the element as an example.
  • the Hubs in the storage queue are all empty, so the code value corresponding to the Hub is all A.
  • the Producer detects whether the code value of the target Hub is A. If the code value of the target Hub is A, the target Hub is determined to be empty, so the Producer writes the element to be written into the target In the value of Hub, and the code value of the Hub is changed to B.
  • the data writing module determines that the storage unit is the target storage unit, then the data writing module By detecting the second field, it can be determined that the target storage unit is not empty. Therefore, the data writing module will search for a new target storage unit again, thereby avoiding out-of-order conflicts.
  • the foregoing storage queue in this embodiment is a class, and its interface is fully compatible with the BlockingQueue of the JDK standard. It can be used without paying additional learning costs.
  • the storage unit in the embodiment of the application includes a field for storing an element and a field for storing a read-write identification.
  • the read-write identification of the storage unit Determine whether the cell is empty, so as to determine whether to access the storage cell to write elements to it, thereby avoiding that the data reading module has not read the element from the storage cell, and the data writing module accesses the storage before the data reading module The problem of out-of-order conflict caused by the unit, thereby improving concurrency efficiency.
  • the foregoing embodiment of the present application solves the technical problem that the blocking queue of the JDK is prone to out-of-order conflicts under high concurrency conditions, resulting in low concurrency efficiency.
  • the above method further includes: the data writing module determines whether the storage queue has a space that allows inserting elements; if there is a storage queue that allows insertion The space of the element enters the step where the data writing module searches for the target storage unit from the storage queue.
  • the data writing module When the storage queue is full, the data writing module is not allowed to continue writing. Therefore, the data writing module needs to determine whether the storage queue is full before determining the target storage module.
  • the Producer first determines whether the storage queue is full. If the storage queue is full, there is no space for inserting elements. If the storage queue is not full, then Make sure that there is room for inserting elements.
  • the data writing module determines whether there is space for inserting elements in the storage queue, including: the data writing module reads the current value of the data write pointer and the current value of the data read pointer; data write The input module obtains the difference between the current value of the data write pointer and the current value of the data read pointer; the data write module compares the difference with the queue length of the storage queue; if the difference is less than the queue length, it determines The storage queue has a space that allows elements to be inserted; if the difference is equal to the queue length of the storage queue, it is determined that there is no space that allows elements to be inserted in the storage queue.
  • the data writing module has a corresponding data writing pointer
  • the data reading module has a corresponding data reading pointer.
  • the data write pointer points to the last storage unit where the data write module puts the element into the storage queue
  • the data read pointer points to the last storage unit where the data read module takes the element out of the storage queue.
  • the values of the two pointers can both be long and increase monotonically.
  • the data writing module only modifies the data writing pointer, and the data reading module only modifies the data reading pointer.
  • the data write module can obtain the data write pointer and the data read pointer from the cache, and determine the storage unit pointed to by the data write pointer and the data read pointer through bitwise operation. Compared with the modulo of the queue length, The AND operation is to determine the offset of the pointer in the storage queue, which consumes less operation and can speed up the operation process.
  • the data write pointer is a Produced pointer
  • the data read pointer is a Consumed pointer
  • the queue length of the storage queue is 2 ⁇ n.
  • the difference between the Produced pointer and the Consumed pointer is now read. If the difference between the Produced pointer and the Consumed pointer is less than 2 ⁇ n, it is determined that the stored queue is not full. If the difference between the Produced pointer and the Consumed pointer is equal to 2 ⁇ n, it is determined that the stored queue is full.
  • the data writing module searches for the target storage unit from the storage queue, including: the data writing module adds one to the current value of the data writing pointer through a comparison and exchange operation to obtain the target Value; the data write module determines that the storage unit indicated by the target value in the storage queue is the target storage unit.
  • the comparison and exchange operation is a CAS operation.
  • the above scheme narrows the critical area between each thread to the CAS modification of the data read pointer and the data write pointer variable through the data read pointer and the data write pointer.
  • the data is lock-free, so a CAS operation is required to ensure that the pointer obtained by the data writing module is the latest pointer.
  • the above-mentioned comparison and operation process of this application may be that after the data write module obtains the data write pointer and the data read pointer from the cache, it writes the data obtained from the cache to the data write pointer and the data in the memory. The pointer is compared. Since the latest pointer is stored in the memory, if the comparison result is consistent, it can be determined that the data write pointer obtained by the data write module from the cache is the latest pointer, and the operation can be increased by one , Get the target value.
  • the data write module needs to read the data write pointer and the data read pointer from the memory again.
  • the Producer adds 1 to the current position of the pointer to obtain the pointer of the target storage unit.
  • the Producer pointer Produced increases by 1 and points to Hub: 2.
  • Hub: 2 is the target storage unit of the Producer.
  • the data writing module judges whether the target storage unit is empty according to the second field of the target storage unit, including: the data writing module reads the second field of the target storage unit, and judges the value of the target storage unit Whether the read-write identification is the second preset value, where the data reading module changes the second field of the target storage unit to the second preset value after reading the data from the target storage unit; if the read-write identification of the target storage unit If it is the second preset value, it is determined that the target storage unit is empty; if the read/write identifier of the target storage unit is not the second preset value, it is determined that the target storage unit is not empty.
  • the second field of the storage unit is changed to the second preset value. Therefore, when the data writing module detects the reading of the second field of the target storage unit When the write identifier is the second preset value, it means that the data reading module has read the elements of the target storage unit. When the data writing module detects that the read/write identifier of the second field of the target storage unit is not the second When the preset value is set, it means that the element in the target storage unit has not been read by the data reading unit, so data cannot be written.
  • the read-write identifier of the second field of each storage unit can be set to a second preset value.
  • the second preset value is obtained by negating the difference between the first preset value and the n-th power of two, where n is used to represent the queue length of the storage queue.
  • the first preset value is determined according to the second preset value.
  • the second preset value is ⁇ (p-2 ⁇ n), where' ⁇ ' is used to indicate the bit inversion operation.
  • the first preset value is the unit identifier of the target storage unit.
  • the unit identifier of the target storage unit is used to indicate the position of the storage unit in the storage queue. As shown in FIG. 3, for a storage queue with 2 ⁇ n storage units, the unit identifier ranges from 0 to (2 ⁇ n- 1), the first preset value is the unit identifier of the target storage unit.
  • the data writing module determines that the read/write identifier of the second field in the target storage unit is ⁇ (2-2 ⁇ n), it writes the element to the target storage unit and sets the second field of the target storage unit.
  • the read-write identifier of the field is modified to 2.
  • the storage structure to which the storage queue belongs further includes a data write linked list. If the storage queue does not have a space that allows inserting elements, the data write module generates a write-waiting object and will wait for the write-in object Insert data into the linked list.
  • the storage structure also includes a data write linked list for when the storage queue is full, the data write module generates a data write object, and saves the data write object in the data write linked list, waiting for the data Read the wakeup of the module.
  • the data written into the linked list is ProducerParker, which supports lock-free and concurrency safety.
  • ProducerParker When the Producer finds that the queue is full, it generates a Parker, puts it at the end of the ProducerParker linked list, and sets the thread Set to idle state.
  • the storage structure to which the storage queue belongs further includes a data reading linked list. If the storage queue does not have an element that is allowed to be read, the data reading module generates an object waiting to be read and will wait to read the object Insert data to read the linked list.
  • the storage structure also includes a data read linked list, which is used when the storage queue is empty, the data read module generates a data read object, and saves the data write object in the data read linked list, waiting for the data Wake-up of write module.
  • the data written into the linked list is ConsumerParkers, which supports lock-free and concurrency safety.
  • ConsumerParkers When the Consumer finds that the queue is empty, it generates a Parker and places it at the end of the ConsumerParkers linked list. The thread is set to idle.
  • the above scheme is based on the self-managed ConsumerParkers and ProducerParkers non-locking linked list to realize Blocking, thereby reducing the overhead of the Consumer or Producer while waiting, and improving the efficiency of resource utilization.
  • the above method also Including: the data writing module searches whether the data reading linked list includes the waiting to be read object; if the data reading linked list includes the waiting to read object, then waking up the data reading module corresponding to the waiting to read object to read the data.
  • the data writing module can check whether there are waiting data reading objects in the data reading linked list every time after writing an element to the storage queue, and when there are data reading objects in the data reading linked list , Wake up the data reading object, and the data reading module corresponding to the data reading object reads the elements in the queue.
  • FIG. 4 is a schematic diagram of a data writing module writing elements to a storage queue according to Embodiment 1 of the present application. The method for reading and writing data in the foregoing embodiment will be described below with reference to FIG. 4.
  • step S51 The Producer reads the Produced and Consumed pointers, and judges whether the difference between Produced and Consumed is less than the queue length. If the difference between Produced and Consumed is less than the queue length, go to step S52, otherwise go to step S56.
  • step S52 The Producer adds 1 to the Produced pointer through the CAS operation, and the obtained value is p. If the CAS operation fails, return to step S51, otherwise continue to perform step S53.
  • the above steps are used to determine when the element in the Hub has been read by Consumer, the status of the Hub is empty, and the Producer is allowed to write the element.
  • S54 The Producer sets the value of the value field in the Hub as the inserted element. And modify the code field to p.
  • the Producer checks the ConsuemrParkers linked list, and if it detects that there is a waiting Parker in the ConsuemrParkers linked list, it takes out the first Parker in ConsumerParks and wakes up the thread therein.
  • the LindormBlockingQueue in the foregoing embodiment of this application uses the code field to resolve conflicts.
  • Producer and Consumer have two rules: 1 Producer must wait for the code to be ⁇ (p-2 ⁇ n) before proceeding. After the operation is completed, modify the code to p; 2Consumer must wait for the code to be c before proceeding. After the operation is completed, modify the code to ⁇ c.
  • the code value in the Hub can be optimized using false sharing padding technology and cacheline dirty read technology. This further improves concurrency and reduces conflicts between threads.
  • the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, of course, it can also be implemented by hardware, but in many cases the former is Better implementation.
  • the technical solution of the present invention essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM/RAM, magnetic disk, The optical disc) includes several instructions to make a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) execute the method of each embodiment of the present invention.
  • FIG. 7 is a flow chart of a method for reading and writing data according to Embodiment 2 of the present application. As shown in FIG. 7, the method is include:
  • Step S71 The data reading module searches for the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, and each storage unit includes: a first field for storing elements and a second field for storing read-write identifiers. Field.
  • the aforementioned data reading module may be a Handler.
  • the storage queue can be a blocking queue used in a distributed database, and the queue is a bounded queue.
  • the above-mentioned read/write identifier is an identifier used to characterize the read/write status of the storage unit, and is used for the data writing module or the data reading module to determine the current read/write status of the storage unit according to the identifier.
  • the read and write status of a storage unit is used to indicate whether its status allows the element to be read or written.
  • the data reading module searches for the target storage unit, and may determine the next storage unit of the current storage unit as the target storage unit every time according to the rules of the queue.
  • FIG. 4 is a schematic diagram of a blocking queue of a distributed database according to Embodiment 1 of the present application.
  • the storage queue may use an array with a length of 2 ⁇ n as Storage structure.
  • Each Hub consists of two fields: value (first field) and code (second field).
  • the value is used to store the elements written by the data write module, and the code is used to store the access control identification in the producer and consumer mode, that is, the above-mentioned read-write identification.
  • step S73 the data reading module determines whether the target storage unit has been written in according to the second field of the target storage unit.
  • the data reading module After finding the target storage unit, the data reading module reads the content in the second field of the target storage unit, and determines whether the target storage unit has been written into the element according to the content of the second field. Still taking Hub including value and code as an example, the data reading module fetches the target Hub, reads the code field of the Hub, and determines whether the target unit has been written into the element according to the code field of the Hub.
  • the content in the code can be A or B.
  • a code value of A indicates that the Hub is empty, and a code value of B indicates that the Hub has been written to the element.
  • the data reading module After the data reading module reads the code value of the Hub, it determines whether it is B, so that it can be determined whether the Hub has been written into the element.
  • Step S75 in the case that the target storage unit has been written into the element, the data reading module reads the element in the target storage unit, and changes the second field of the target storage unit to a first preset value, where the first The preset value is used to indicate that the target storage unit is empty.
  • the data reading module determines that the target storage cell has been written to the element, the element is read from the storage cell. If the target storage unit is not empty, the data reading module can determine a new target storage unit, and enter the step of determining whether the new target storage unit is written into an element, until an empty storage unit is found.
  • the data reading module After the data reading module reads the element from the target storage unit, the state of the target storage unit has changed, so the data reading module also needs to change the read and write identifier in the second field of the target storage unit to change the target storage The status of the unit.
  • the code value is A to indicate that the Hub is empty, and the code value is B to indicate that the Hub has been written into the element as an example.
  • the Consumer data reading module detects whether the code value of the target Hub is B. If the code value of the target Hub is B, it is determined that the target Hub has been written to the element, so the Consumer reads the element from the value of the Hub, and the Hub Change the code value to A.
  • the data writing module determines that the storage unit is the target storage unit, then the data writing module By detecting the second field, it can be determined that the target storage unit is not empty. Therefore, the data writing module will search for a new target storage unit again, thereby avoiding out-of-order conflicts.
  • the storage unit in the embodiment of the present application includes a field for storing elements and a field for storing read-write identification. Before the data reading module reads the elements in the storage queue storage unit, it is determined by the read-write identification of the storage unit Whether the cell includes the element that has been written, so as to determine whether to access the storage cell to read the element from it, thereby avoiding that the data writing module has not yet written the element to the storage cell, and the data reading module precedes the data writing module The problem of out-of-order conflicts caused by access to storage units, thereby improving concurrency efficiency.
  • the foregoing embodiment of the present application solves the technical problem that the blocking queue of the JDK is prone to out-of-order conflicts under high concurrency conditions, resulting in low concurrency efficiency.
  • the above method further includes: the data reading module determines whether the storage queue has elements that are allowed to be read; The fetched element enters the step where the data reading module reads the element in the target storage unit.
  • the data reading module When the storage queue is empty, the data reading module is not allowed to continue reading. Therefore, the data reading module needs to check whether the storage queue is empty before searching for the target storage module.
  • the Consumer after receiving the data reading task, the Consumer first determines whether the storage queue is empty. If the storage queue is empty, there is no space allowed to read the element. If the storage queue is not empty, , It is determined that there is a space that allows the element to be read.
  • the data reading module determines whether there are elements that are allowed to be read in the storage queue, including: the data reading module reads the current value of the data write pointer and the current value of the data read pointer; data read The fetch module obtains the difference between the current value of the data write pointer and the current value of the data read pointer; if the difference is greater than zero, it is determined that the storage queue has elements that are allowed to be read; if the difference is equal to the queue length of the storage queue , It is determined that there are no elements allowed to be read in the storage queue.
  • the data writing module has a corresponding data writing pointer
  • the data reading module has a corresponding data reading pointer.
  • the data write pointer points to the last storage unit where the data write module puts the element into the storage queue
  • the data read pointer points to the last storage unit where the data read module takes the element out of the storage queue.
  • the values of the two pointers can both be long and increase monotonically.
  • the data writing module only modifies the data writing pointer, and the data reading module only modifies the data reading pointer.
  • the data write module can obtain the data write pointer and the data read pointer from the cache, and determine the storage unit pointed to by the data write pointer and the data read pointer through bitwise operation. Compared with the modulo of the queue length, The AND operation is to determine the offset of the pointer in the storage queue, which consumes less operation and can speed up the operation process.
  • the data write pointer is a Produced pointer
  • the data read pointer is a Consumed pointer
  • the queue length of the storage queue is 2 ⁇ n.
  • the data reading module searches for the target storage unit from the storage queue, including: the data reading module adds to the current value of the data reading pointer through a comparison and exchange operation 1. Obtain the target value; the data reading module determines that the storage unit indicated by the target value in the storage queue is the target storage unit.
  • the comparison and exchange operation is a CAS operation.
  • the data is unlocked. Therefore, a CAS operation is required to ensure that the pointer obtained by the data reading module is the latest pointer.
  • the above-mentioned comparison and operation process of this application may be that after the data reading module obtains the data write pointer and the data read pointer from the cache, the data read pointer obtained from the cache is read from the data in the memory. The pointers are compared. Since the latest pointers are stored in the memory, if the comparison results are consistent, it can be determined that the data reading pointer obtained by the data reading module from the cache is the latest pointer, which can be added by one. , Get the target value.
  • the data reading module needs to read the data writing pointer and the data reading pointer from the memory again.
  • the Producer adds 1 to the current position of the pointer to obtain the pointer of the target storage unit. As shown in FIG. 4, the pointer Consumed of the Consumer increases by 1 and points to Hub: 1. Then Hub: 1 is the target storage unit of the Producer.
  • the data reading module determines whether the target storage unit has been written according to the second field of the target storage unit, including: the data reading module reads the second field of the target storage unit to determine the target storage Whether the read/write identifier of the unit is the second preset value, where the data writing module changes the second field of the target storage unit to the second preset value after writing the element to the target storage unit; If the write identifier is the second preset value, it is determined that the target storage unit has been written; if the read/write identifier of the target storage unit is not the second preset value, it is determined that the target storage unit is not written.
  • the data writing module reads the second field of the target storage unit, and determines whether the read/write identifier of the target storage unit is the second preset value.
  • the data reading module reads the data from the target storage unit, and then sets the target storage unit's Change the second field to the second preset value;
  • the read/write identifier of the target storage unit is the second preset value, it is determined that the target storage unit is empty;
  • the read/write identifier of the target storage unit is not the second preset value, it is determined that the target storage unit is not empty.
  • the second field of the storage unit is changed to the second preset value. Therefore, when the data reading module detects the reading and writing of the second field of the target storage unit When the identifier is the second preset value, it means that the data writing module has written the element to the target storage unit, and when the data reading module detects that the read/write identifier of the second field of the target storage unit is not the second preset value , It means that the target memory cell has not been written into the element, so it cannot be read.
  • the first preset value and the second preset value are opposite to each other.
  • the second preset value is ⁇ c, where' ⁇ ' is used to indicate the bit inversion operation.
  • the second preset value is the unit identifier of the target storage unit.
  • the unit identifier of the target storage unit is used to indicate the position of the storage unit in the storage queue. As shown in FIG. 4, for a storage queue with 2 ⁇ n storage units, the unit identifier ranges from 0 to (2 ⁇ n- 1), the first preset value is the unit identifier of the target storage unit.
  • the data reading unit determines that the read/write identifier of the second field in the target storage unit is 1, it reads the element in the target storage unit, and modifies the read/write identifier of the second field of the target storage unit to -1.
  • the storage structure to which the storage queue belongs further includes a data reading linked list. If the storage queue does not have an element that is allowed to be read, the data reading module generates an object waiting to be read and will wait to read the object Insert data to read the linked list.
  • the storage structure includes a data read linked list, which is used when the storage queue is empty, the data read module generates a data read object, and saves the data write object in the data read linked list, waiting for data writing The wake-up of the incoming module.
  • the data written to the linked list is ConsumerParkers, which supports lock-free and concurrency security.
  • ConsumerParkers When the Consumer finds that the queue is empty, it generates a Parker and places it at the end of the ConsumerParkers linked list. The thread is set to idle.
  • the storage structure to which the storage queue belongs further includes a data write linked list. If the storage queue does not have a space that allows inserting elements, the data write module generates a write-waiting object and will wait for the write-in object Insert data into the linked list.
  • the storage structure also includes a data write linked list for when the storage queue is full, the data write module generates a data write object, and saves the data write object in the data write linked list, waiting for the data Read the wakeup of the module.
  • the data written to the linked list is ProducerParker, which supports lock-free and concurrency safety.
  • ProducerParker When the Producer finds that the queue is full, it will generate a Parker, place it at the end of the ProducerParker linked list, and set the thread Set to idle state.
  • the above method further includes: a data reading module Look up whether the data write linked list includes the object waiting to be written; if the data write linked list includes the object waiting to be written, the data write module corresponding to the object waiting to be written is awakened for data writing.
  • the data reading module can check whether there is a data writing object waiting to be written in the data writing linked list after reading elements from the storage queue, and there is data writing in the data writing linked list
  • the data is written into the object to wake up, and the data write module corresponding to the data write object writes the element into the storage queue.
  • FIG. 8 is a schematic diagram of a data reading module reading storage queue elements according to Embodiment 2 of the present application. The method for reading and writing data in the foregoing embodiment will be described below with reference to FIG. 8.
  • step S81 The Consumer reads the Produced and Consumed pointers, and judges whether the difference between Produced and Consumed is greater than 0, and the difference between Produced and Consumed is greater than 0, then go to step S82, otherwise go to step S86.
  • step S82 the Consumer tries to operate the CAS by adding 1 to the Consumed pointer, and the obtained value is c. If the CAS operation fails, return to step S81, otherwise continue to perform step S83.
  • the Consumer sets the value of the value field in the Hub to be empty, and modifies the code field to ⁇ c.
  • the Consumer checks the ProducerParkers linked list, and if it detects that the ProducerParkers linked list has Parkers, it will take out the first Parker in the ProducerParkers and wake up the threads in it.
  • the Consumer In S86, the Consumer generates a Parker object and inserts it into the end of the ConsumerParkers list, and waits for the Producer to wake up. When Consuemr is awakened, it returns to step S81 to continue execution.
  • FIG. 9 is a schematic diagram of a data reading and writing device according to Embodiment 3 of the present application. As shown in FIG. 9, the device 900 includes:
  • the searching module 902 is used for the data writing module to find the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, and each storage unit includes at least: a first field for storing elements and a first field for storing reading Write the second field of the logo.
  • the judging module 904 is used for the data writing module to judge whether the target storage unit is empty according to the second field of the target storage unit.
  • the writing module 906 is used to write the element to be written into the first field of the target storage unit and change the second field of the target storage unit to the first preset when the target storage unit is empty. Setting value, where the first preset value is used to indicate that the target storage unit has been written into the element.
  • the above search module 902 and the search module 102 correspond to steps S21 to S25 in Embodiment 1.
  • the two modules and the corresponding steps implement the same examples and application scenarios, but are not limited to the above embodiments.
  • One public content It should be noted that, as a part of the device, the above-mentioned modules can run in the computer terminal 10 provided in the first embodiment.
  • the above-mentioned apparatus further includes: a determining module, configured to determine whether the data writing module has a space for inserting elements in the storage queue before the data writing module searches for the target storage unit from the storage queue; The module is used to enter the step of finding the target storage unit from the storage queue by the data writing module if there is space for inserting elements in the storage queue.
  • the determining module includes: a first acquisition submodule, which is used for the data writing module to read the current value of the data write pointer and the current value of the data read pointer; and the second acquisition submodule uses The data write module obtains the difference between the current value of the data write pointer and the current value of the data read pointer; the comparison sub-module is used for the data write module to compare the difference with the queue length of the storage queue ; The first determining sub-module is used to determine if the difference is less than the length of the queue, then it is determined that there is space for inserting elements in the storage queue; the second determining sub-module is used to determine that the storage queue is not allowed if the difference is equal to the length of the storage queue There is room for inserting elements.
  • a first acquisition submodule which is used for the data writing module to read the current value of the data write pointer and the current value of the data read pointer
  • the second acquisition submodule uses The data write module obtains the difference between the current value of the data write point
  • the search module includes: an operation sub-module for the data writing module to add one to the current value of the data writing pointer through comparison and exchange operations to obtain the target value;
  • the sub-module is used for the data writing module to determine that the storage unit indicated by the target value in the storage queue is the target storage unit.
  • the judging module includes: a judging sub-module for the data writing module to read the second field of the target storage unit and judge whether the read/write identifier of the target storage unit is a second preset value, where After reading the data from the target storage unit, the data reading module changes the second field of the target storage unit to the second preset value; the fourth determining sub-module is used for if the read/write identification of the target storage unit is the second preset value If the value is set, it is determined that the target storage unit is empty; the fifth determining sub-module is configured to determine that the target storage unit is not empty if the read/write identifier of the target storage unit is not the second preset value.
  • the second preset value is obtained by negating the difference between the first preset value and the n-th power of two, where n is used to represent the queue length of the storage queue.
  • the first preset value is the unit identifier of the target storage unit.
  • the storage structure to which the storage queue belongs further includes a data write linked list. If the storage queue does not have a space that allows inserting elements, the data write module generates a write-waiting object and will wait for the write-in object Insert data into the linked list.
  • the storage structure to which the storage queue belongs further includes a data reading linked list. If the storage queue does not have an element that is allowed to be read, the data reading module generates an object waiting to be read and will wait to read the object Insert data to read the linked list.
  • the above device further includes: a search again module, configured to write the element to be written into the first field of the target storage unit in the data writing module, and change the second field of the target storage unit
  • the data writing module looks up whether the object waiting to be read is included in the data reading linked list; the wake-up module is used to wake up the corresponding object waiting to be read if the data reading linked list includes the waiting object
  • the data reading module performs data reading.
  • FIG. 10 is a schematic diagram of a data reading and writing device according to Embodiment 4 of the present application. As shown in FIG. 10, the device 100 includes:
  • the search module 102 is used for the data reading module to search for the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, and each storage unit includes: a first field for storing elements and a read-write identifier for storing The second field.
  • the judging module 104 is used for the data reading module to judge whether the target storage unit has been written in according to the second field of the target storage unit.
  • the reading module 106 is configured to read the element in the target storage unit and change the second field of the target storage unit to the first preset value when the target storage unit has been written into the element.
  • the first preset value is used to indicate that the target storage unit is empty.
  • the above-mentioned search module 102, judgment module 104, and reading module 106 correspond to steps S71 to S75 in Embodiment 2.
  • the two modules implement the same examples and application scenarios as the corresponding steps, but It is not limited to the content disclosed in the first embodiment. It should be noted that, as a part of the device, the above-mentioned modules can run in the computer terminal 10 provided in the first embodiment.
  • the above device further includes: a determining module, configured to determine whether the data reading module has an element that allows reading in the storage queue before the data reading module searches for the target storage unit from the storage queue; The module is used to enter the step of reading the elements in the target storage unit by the data reading module if there are elements that are allowed to be read in the storage queue.
  • a determining module configured to determine whether the data reading module has an element that allows reading in the storage queue before the data reading module searches for the target storage unit from the storage queue; The module is used to enter the step of reading the elements in the target storage unit by the data reading module if there are elements that are allowed to be read in the storage queue.
  • the determining module includes: a first acquisition sub-module for the data reading module to read the current value of the data write pointer and the current value of the data read pointer; the second acquisition sub-module uses The data read module obtains the difference between the current value of the data write pointer and the current value of the data read pointer; the first determining sub-module is used to determine if the difference is greater than zero, that the storage queue is allowed to be read Element; the second determining sub-module is used to determine that if the difference is equal to the queue length of the storage queue, it is determined that the storage queue does not have an element that allows reading.
  • the search module includes: an operation sub-module for the data reading module to add one to the current value of the data reading pointer through comparison and exchange operations to obtain the target value;
  • the sub-module is used for the data reading module to determine that the storage unit indicated by the target value in the storage queue is the target storage unit.
  • the judging module includes: a judging sub-module for the data reading module to read the second field of the target storage unit and judge whether the read/write identifier of the target storage unit is a second preset value, where After the data writing module writes the element into the target storage unit, it changes the second field of the target storage unit to the second preset value; the fourth determining sub-module is used for if the read/write identifier of the target storage unit is the second preset value. If the value is set, it is determined that the target storage unit has been written; the fifth determining sub-module is configured to determine that the target storage unit has not been written if the read/write identifier of the target storage unit is not the second preset value.
  • the first preset value and the second preset value are opposite to each other.
  • the second preset value is the unit identifier of the target storage unit.
  • the storage structure to which the storage queue belongs further includes a data reading linked list. If the storage queue does not have an element that is allowed to be read, the data reading module generates an object waiting to be read and will wait to read the object Insert data to read the linked list.
  • the storage structure to which the storage queue belongs further includes a data write linked list. If the storage queue does not have a space that allows inserting elements, the data write module generates a write-waiting object and will wait for the write-in object Insert data into the linked list.
  • the above device further includes: a search again module, configured to read the element in the target storage unit in the data reading module, and change the second field of the target storage unit to the first preset value After that, the data reading module finds whether the data write linked list includes the object waiting to be written; the wake-up module is used to wake up the data write module corresponding to the waiting write object if the data write linked list includes the object waiting to be written.
  • a search again module configured to read the element in the target storage unit in the data reading module, and change the second field of the target storage unit to the first preset value
  • the data reading module finds whether the data write linked list includes the object waiting to be written
  • the wake-up module is used to wake up the data write module corresponding to the waiting write object if the data write linked list includes the object waiting to be written.
  • the embodiments of the present invention may provide a computer terminal, and the computer terminal may be any computer terminal device in a computer terminal group.
  • the above-mentioned computer terminal may also be replaced with a terminal device such as a mobile terminal.
  • the foregoing computer terminal may be located in at least one network device among multiple network devices in the computer network.
  • the above-mentioned computer terminal can execute the program code of the following steps in the data reading and writing method: the data writing module finds the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, each The unit includes at least: a first field for storing elements and a second field for storing read-write identifiers; the data writing module judges whether the target storage unit is empty according to the second field of the target storage unit; the target storage unit is empty In the case of, the data writing module writes the element to be written into the first field of the target storage unit, and changes the second field of the target storage unit to a first preset value, where the first preset value is used to indicate The target storage unit has been written to the element.
  • FIG. 11 is a structural block diagram of a computer terminal according to Embodiment 5 of the present invention.
  • the computer terminal A may include: one or more (only one is shown in the figure) processor 1102, memory 1104, and peripheral interface 1106.
  • the memory can be used to store software programs and modules, such as the program instructions/modules corresponding to the method and device for reading and writing data in the embodiments of the present invention.
  • the processor executes various programs and modules by running the software programs and modules stored in the memory. Functional application and data processing, that is, to achieve the above-mentioned data reading and writing methods.
  • the memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memories.
  • the memory may further include a memory remotely provided with respect to the processor, and these remote memories may be connected to the terminal A via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
  • the processor can call the information and application programs stored in the memory through the transmission device to perform the following steps: the data writing module finds the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, and each storage unit is at least Including: the first field used to store the element and the second field used to store the read-write identifier; the data writing module judges whether the target storage unit is empty according to the second field of the target storage unit; in the case that the target storage unit is empty Next, the data writing module writes the element to be written into the first field of the target storage unit, and changes the second field of the target storage unit to a first preset value, where the first preset value is used to indicate the target storage The cell has been written to the element.
  • the above-mentioned processor may also execute the program code of the following steps: before the data writing module finds the target storage unit from the storage queue, the data writing module determines whether there is space in the storage queue that allows inserting elements; if the storage queue exists If the space where the element is allowed to be inserted, the data writing module enters the step of finding the target storage unit from the storage queue.
  • the aforementioned processor may also execute the program code of the following steps: the data write module reads the current value of the data write pointer and the current value of the data read pointer; the data write module acquires the current value of the data write pointer The difference between the current value of the data read pointer and the data read pointer; the data write module compares the difference with the queue length of the storage queue; if the difference is less than the queue length, it is determined that there is room for inserting elements in the storage queue; if If the difference is equal to the queue length of the storage queue, it is determined that there is no space for inserting elements in the storage queue.
  • the above-mentioned processor may also execute the program code of the following steps: the data writing module adds one to the current value of the data writing pointer through comparison and exchange operations to obtain the target value; the data writing module determines the target The storage unit indicated by the value in the storage queue is the target storage unit.
  • the above-mentioned processor may also execute the program code of the following steps: the data writing module reads the second field of the target storage unit, and judges whether the read/write identifier of the target storage unit is the second preset value, where the data read After the fetch module reads the data from the target storage unit, it changes the second field of the target storage unit to the second preset value; if the read/write identifier of the target storage unit is the second preset value, it is determined that the target storage unit is empty; If the read/write identifier of the target storage unit is not the second preset value, it is determined that the target storage unit is not empty.
  • the difference between the first preset value and the n-th power of two is reversed to obtain the second preset value, where n is used to represent the queue length of the storage queue.
  • the first preset value is the unit identifier of the target storage unit.
  • the storage structure to which the storage queue belongs also includes a data write linked list. If there is no space in the storage queue that allows inserting elements, the data write module generates objects waiting to be written, and inserts the objects waiting to be written into the linked list. .
  • the storage structure to which the storage queue belongs also includes a data reading linked list. If there are no elements allowed to be read in the storage queue, the data reading module generates a waiting-reading object and inserts the waiting-reading object into the data reading linked list. .
  • the foregoing processor may also execute the program code of the following steps: write the element to be written into the first field of the target storage unit in the data writing module, and change the second field of the target storage unit to the first preset.
  • the data writing module After setting the value, the data writing module searches whether the data reading linked list includes the waiting to be read object; if the data reading linked list includes the waiting to read object, it wakes up the data reading module corresponding to the waiting to read object to read the data.
  • the storage unit in the embodiment of the application includes a field for storing an element and a field for storing a read-write identification.
  • the read-write identification of the storage unit Determine whether the cell is empty, so as to determine whether to access the storage cell to write elements to it, thereby avoiding that the data reading module has not read the element from the storage cell, and the data writing module accesses the storage before the data reading module.
  • the structure shown in Figure 11 is only for illustration, and the computer terminal can also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, an applause computer, and a mobile Internet Device (MID). ), PAD and other terminal equipment.
  • FIG. 11 does not limit the structure of the above electronic device.
  • the computer terminal A may also include more or fewer components (such as a network interface, a display device, etc.) than those shown in FIG. 11, or have a configuration different from that shown in FIG. 11.
  • the program can be stored in a computer-readable storage medium, which can be Including: flash disk, read-only memory (Read-Only Memory, ROM), random access device (Random Access Memory, RAM), magnetic disk or optical disk, etc.
  • the embodiment of the present invention also provides a storage medium.
  • the foregoing storage medium may be used to store the program code executed by the data reading and writing method provided in the foregoing embodiment 1.
  • the foregoing storage medium may be located in any computer terminal in a computer terminal group in a computer network, or located in any mobile terminal in a mobile terminal group.
  • the storage medium is configured to store program code for performing the following steps: the data writing module finds the target storage unit from the storage queue, where the storage queue includes a plurality of storage units, each Each storage unit includes at least: a first field for storing elements and a second field for storing read-write identifiers; the data writing module determines whether the target storage unit is empty according to the second field of the target storage unit; If it is empty, the data writing module writes the element to be written into the first field of the target storage unit, and changes the second field of the target storage unit to the first preset value, where the first preset value is used Yu indicates that the target memory cell has been written to the element.
  • the disclosed technical content can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division.
  • multiple units or components may be combined or may be Integrate into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of units or modules, and may be in electrical or other forms.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • the functional units in the various embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
  • the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the technical solution of the present invention essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , Including several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present invention.
  • the aforementioned storage media include: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program code .

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种数据的读写方法和装置。其中,该方法包括:数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空;在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。本发明解决了JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的技术问题。

Description

数据的读写方法和装置
本申请要求2019年03月06日递交的申请号为201910168960.1、发明名称为“数据的读写方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及数据处理领域,具体而言,涉及一种数据的读写方法和装置。
背景技术
分布式数据库系统是指利用高速计算机网络,将物理上分散的多个数据存储单元连接起来组成一个逻辑上统一的数据库。分布式数据库的基本思想是原来集中式数据库中的数据分散存储到多个通过网络连接的数据存储节点上,以获取更大的存储容量和更高的访问量。但分布式数据库在面对高并发的情况下,多线程并行运行且无法保证各个线程间指令的运行顺序,因此容易发生乱序冲突的问题。
针对JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的问题,目前尚未提出有效的解决方案。
发明内容
本发明实施例提供了一种数据的读写方法和装置,以至少解决JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的技术问题。
根据本发明实施例的一个方面,提供了一种数据的读写方法,包括:数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空;在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
根据本发明实施例的另一方面,还提供了一种数据的读写方法,包括:数据读取模块从存储队列中查找目标存储单元,其中,存储队列包括多个存储单元,每个存储单元包括:用于存放元素的第一字段和用于存放读写标识的第二字段;数据读取模块根据目标存储单元的第二字段判断目标存储单元是否已被写入;在目标存储单元已被写入元素的情况下,数据读取模块读取目标存储单元内的元素,并将目标存储单元的第二字段更 改为第一预设值,其中,第一预设值用于表示目标存储单元为空。
根据本发明实施例的另一方面,还提供了一种数据的读写装置,包括:查找模块,用于数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;判断模块,用于数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空;写入模块,用于在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
根据本发明实施例的另一方面,还提供了一种数据的读写装置,包括:查找模块,用于数据读取模块从存储队列中查找目标存储单元,其中,存储队列包括多个存储单元,每个存储单元包括:用于存放元素的第一字段和用于存放读写标识的第二字段;判断模块,用于数据读取模块根据目标存储单元的第二字段判断目标存储单元是否已被写入;写入模块,用于在目标存储单元已被写入元素的情况下,数据读取模块读取目标存储单元内的元素,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元为空。
在本发明实施例中的存储单元中包括用于存储元素的字段和用于存储读写标识的字段,在数据写入模块向存储队列的存储单元中写入元素之前,通过存储单元的读写标识确定该单元是否为空,从而确定是否访问该存储单元以向其写入元素,进而可以避免数据读取模块还未从存储单元读取元素,数据写入模块就先于数据读取模块访问存储单元所导致的乱序冲突的情况,解决了JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的技术问题,提高了并发效率。
附图说明
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:
图1示出了一种用于实现数据的读写方法的计算机终端(或移动设备)的硬件结构框图;
图2是根据本申请实施例1的数据的读写方法的流程图;
图3是根据本申请实施例1的一种分布式数据库的阻塞队列的示意图;
图4是根据本申请实施例1的一种数据写入模块向存储队列写入元素的示意图;
图5是相差倍数为2^n的线程乱序访问同一个Hub的示意图;
图6是根据本申请实施例1的一种相差倍数为2^n的线程读写数据的示意图;
图7是根据本申请实施例2的一种数据的读写方法的流程;
图8是根据本申请实施例2的一种数据读取模块读取存储队列元素的示意图;
图9是根据本申请实施例3的一种数据的读写装置的示意图;
图10是根据本申请实施例4的一种数据的读写装置的示意图;以及
图11是根据本申请实施例5的一种计算机终端的结构框图。
具体实施方式
为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分的实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本发明保护的范围。
需要说明的是,本发明的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本发明的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
首先,在对本申请实施例进行描述的过程中出现的部分名词或术语适用于如下解释:
Queue:即队列,是一种常见的数据结构,队列是一种操作受限制的线性表。进行插入操作的端称为队尾,进行取出操作的端称为队头。
元素:用于表示对队列进行插入和取出操作的基本单位。
有界队列:指的是队列的一种特殊形式,队列的长度存在上限。当队列中的元素个数等于队列长度时,队列为满的状态。
Producer:即生产者,本申请中的生产者用于表示对队列进行插入操作的行为模块。
Consumer:即消费者,本申请中的消费者用于表示对队列进行取出操作的行为模块。
BlockingQueue:即阻塞队列,阻塞队列在队列的基础上,支持阻塞等待。当队列为 空时,消费者等待队列中有元素时再取出。当队列为满时,生产者等待队列不为满时再插入。
Handler:Lindorm的内部对象,负责执行请求。一个Handler对应于一个线程。
JDK:即Java Development Kit,JDK是整个Java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。
RPC模块:即Remote Procedure Call,RPC是远程过程调用的简称,RPC模块是实现远程过程调用的程序模块。
Cacheline:高速缓存块,CPU从内存读取或写入数据的最小单位。X86CPU一般Cacheline大小为64Byte。
Lindorm:一种面向海量数据在线处理的分布式数据库。
LindormBlockingQueue:是本申请提出的一种兼容JDK BlockingQueue接口的阻塞队列。主要用于Lindorm内部RPC模块与Handler进行RPC请求暂存与传递。
false-sharing-padding:false-sharing是伪共享,指的是计算机体系架构中,cpu会以cacheline为最小单位,将内存数据缓存到cpu cache中,同时对相邻的无关变量做修改。由于它们可能处于同一cacheline中,导致性能的衰退。false-sharing-padding指的是通过对变量前后增加无意义的填充空间,使其独占一cacheline,避免false-sharing。
cacheline dirty read:一种基于cpu cache的优化策略。指部分场合不需要知道内存中共享变量的精确值时,允许从cpu cache中进行脏读。这种策略可以加速程序的运行。
实施例1
根据本发明实施例,还提供了一种数据的读写方法的实施例,需要说明的是,在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行,并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。
本申请实施例一所提供的方法实施例可以在移动终端、计算机终端或者类似的运算装置中执行。图1示出了一种用于实现数据的读写方法的计算机终端(或移动设备)的硬件结构框图。如图1所示,计算机终端10(或移动设备10)可以包括一个或多个(图中采用102a、102b,……,102n来示出)处理器102(处理器102可以包括但不限于微处理器MCU或可编程逻辑器件FPGA等的处理装置)、用于存储数据的存储器104、以及用于通信功能的传输模块。除此以外,还可以包括:显示器、输入/输出接口(I/O接口)、 通用串行总线(USB)端口(可以作为I/O接口的端口中的一个端口被包括)、网络接口、电源和/或相机。本领域普通技术人员可以理解,图1所示的结构仅为示意,其并不对上述电子装置的结构造成限定。例如,计算机终端10还可包括比图1中所示更多或者更少的组件,或者具有与图1所示不同的配置。
应当注意到的是上述一个或多个处理器102和/或其他数据处理电路在本文中通常可以被称为“数据处理电路”。该数据处理电路可以全部或部分的体现为软件、硬件、固件或其他任意组合。此外,数据处理电路可为单个独立的处理模块,或全部或部分的结合到计算机终端10(或移动设备)中的其他元件中的任意一个内。如本申请实施例中所涉及到的,该数据处理电路作为一种处理器控制(例如与接口连接的可变电阻终端路径的选择)。
存储器104可用于存储应用软件的软件程序以及模块,如本发明实施例中的数据的读写方法对应的程序指令/数据存储装置,处理器102通过运行存储在存储器104内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述的数据的读写方法。存储器104可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器104可进一步包括相对于处理器102远程设置的存储器,这些远程存储器可以通过网络连接至计算机终端10。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
传输装置用于经由一个网络接收或者发送数据。上述的网络具体实例可包括计算机终端10的通信供应商提供的无线网络。在一个实例中,传输装置包括一个网络适配器(Network Interface Controller,NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输装置可以为射频(Radio Frequency,RF)模块,其用于通过无线方式与互联网进行通讯。
显示器可以例如触摸屏式的液晶显示器(LCD),该液晶显示器可使得用户能够与计算机终端10(或移动设备)的用户界面进行交互。
此处需要说明的是,在一些可选实施例中,上述图1所示的计算机设备(或移动设备)可以包括硬件元件(包括电路)、软件元件(包括存储在计算机可读介质上的计算机代码)、或硬件元件和软件元件两者的结合。应当指出的是,图1仅为特定具体实例的一个实例,并且旨在示出可存在于上述计算机设备(或移动设备)中的部件的类型。
在上述运行环境下,本申请提供了如图2所示的数据的读写方法。图2是根据本申请实施例1的数据的读写方法的流程图。
步骤S21,数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括 多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段。
具体的,上述数据写入模块可以是RPCReader。存储队列既可以是应用在分布式数据库中的阻塞队列,该队列为一个有界队列。上述读写标识是用于表征存储单元的读写状态的标识,用于数据写入模块或数据读取模块根据该标识来确定存储单元当前的读写状态。存储单元的读写状态用于表示其状态是否允许被读取或被写入元素。
数据写入模块确定目标存储单元,可以是根据队列的规则,每次确定当前的存储单元的下一个存储单元为目标存储单元。
图3是根据本申请实施例1的一种分布式数据库的阻塞队列的示意图,结合图3所示,在一种可选的实施例中,存储队列可以使用一个长度为2^n的数组作为存储结构。数组中总共有2^n个Hub(存储单元)。每个Hub由value(第一字段)与code(第二字段)两个字段构成。value用于存放数据写入模块写入的元素,code用于存放生产者与消费者模式下的访问控制标识,即上述读写标识。
步骤S23,数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空。
数据写入模块确定目标存储单元后,读取目标存储单元的第二字段中的内容,并根据第二字段的内容确定目标存储单元是否为空。仍以Hub包括value与code为例,数据写入模块取出目标Hub,并读取Hub的code字段,根据Hub的code字段来确定目标单元是否为空。
在一种可选的实施例中,code中的内容可以为A或B两种。code值为A表示Hub为空,code值为B表示Hub已被写入元素。数据写入模块读取Hub的code值后,判断其是否为A,从而可以确定该Hub是否为空。
步骤S25,在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
在上述步骤中,仅当数据写入模块确定目标存储单元为空的情况下,向存储单元写入元素。如果目标存储单元不为空,则数据写入模块可以确定新的目标存储单元,并进入确定新的目标存储单元是否为空的步骤,直至查找到为空的存储单元。
在数据写入模块将待写入元素写入目标存储单元后,该目标存储单元的状态已经发生变更,因此数据写入模块还需要更改目标存储单元的第二字段中的读写标识,以更改目标存储单元的状态。
在一种可选的实施例中,结合图3所示,仍以code值为A表示Hub为空,code值 为B表示Hub已被写入元素为例。队列在初始状态下,存储队列中的Hub均为空,因此Hub对应的code值均为A。数据写入模块在向Hub的value中写入一个元素后,还需要将该Hub的code值更改为B。在非初始状态下,Producer(数据写入模块)检测目标Hub的code值是否为A,如果目标Hub的code值为A,则确定目标Hub为空,因此Producer将待写入的元素写入目标Hub的value中,并该Hub的code值更改为B。
需要说明的是,如果一个存储单元被写入了元素,但在数据读取模块读取该存储单元中的元素之前,数据写入模块确定了该存储单元为目标存储单元,则数据写入模块对其第二字段进行检测即可确定目标存储单元不为空,因此数据写入模块会重新查找新的目标存储单元,从而避免了乱序冲突。
还需要说明的是,本实施例的上述存储队列是一个类,其接口完全兼容JDK标准的BlockingQueue。无需付出额外学习成本即可使用。
本申请实施例中的存储单元中包括用于存储元素的字段和用于存储读写标识的字段,在数据写入模块向存储队列的存储单元中写入元素之前,通过存储单元的读写标识确定该单元是否为空,从而确定是否访问该存储单元以向其写入元素,进而可以避免数据读取模块还未从存储单元读取元素,数据写入模块就先于数据读取模块访问存储单元所导致的乱序冲突的问题,进而提高并发效率。
由此,本申请上述实施例解决了JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的技术问题。
作为一种可选的实施例,在数据写入模块从存储队列中查找目标存储单元之前,上述方法还包括:数据写入模块判断存储队列是否存在允许插入元素的空间;如果存储队列存在允许插入元素的空间,则进入数据写入模块从存储队列中查找目标存储单元的步骤。
当存储队列为满时,不允许数据写入模块继续写入,因此数据写入模块在确定目标存储模块之前,还需要存储队列是否已满。
在一种可选的实施例中,Producer在获取到待写入元素后,首先判断存储队列是否已满,如果存储队列已满,则不存在允许插入元素的空间,如果存储队列未满,则确定存在允许插入元素的空间。
作为一种可选的实施例,数据写入模块判断存储队列是否存在允许插入元素的空间,包括:数据写入模块读取数据写入指针的当前值和数据读取指针的当前值;数据写入模块获取数据写入指针的当前值和数据读取指针的当前值之间的差值;数据写入模块将差值与存储队列的队列长度进行比对;如果差值小于队列长度,则确定存储队列存在允许插入元素的空间;如果差值等于存储队列的队列长度,则确定存储队列不存在允许插入 元素的空间。
在上述方案中,数据写入模块具有对应的数据写入指针,数据读取模块具有对应的数据读取指针。数据写入指针指向数据写入模块将元素放入存储队列的最后一个存储单元,而数据读取指针指向数据读取模块将元素取出存储队列的最后一个存储单元。两个指针的值均可以为long型并单调递增。数据写入模块仅修改数据写入指针,数据读取模块仅修改数据读取指针。
数据写入模块可以从缓存中获取数据写入指针和数据读取指针,并通过与位运算确定数据写入指针与数据读取指针所指向的存储单元,与对队列的长度取模相比,与位运算即为确定指针在存储队列中的偏移量,运算消耗较小,进而能够加速运算过程。
在一种可选的实施例中,数据写入指针为Produced指针,数据读取指针为Consumed指针,存储队列的队列长度为2^n。在Producer确定目标存储单元前,现读取Produced指针和Consumed指针的差值。如果Produced指针和Consumed指针的差值小于2^n,则确定存储的队列不满,如果Produced指针和Consumed指针的差值等于2^n,则确定存储的队列已满。
作为一种可选的实施例,数据写入模块从存储队列中查找目标存储单元,包括:数据写入模块通过比较并交换操作,在数据写入指针的当前值的基础上加一,得到目标值;数据写入模块确定目标值在存储队列中所指示的存储单元为目标存储单元。
比较并交换操作为CAS操作,上述方案通过数据读取指针与数据写入指针将各个线程间的临界区缩小至对数据读取指针和数据写入指针变量的CAS修改上。在上述方案中,数据是无锁的,因此需要进行CAS操作来确保数据写入模块获取的指针是最新的指针。具体的,本申请上述的比较并操作过程可以是,数据写入模块从缓存中获取数据写入指针和数据读取指针后,将从缓存中获取的数据写入指针与内存中的数据写入指针进行比对,由于内存中保存的是最新的指针,因此如果比对结果为一致,则可以确定数据写入模块从缓存获取的数据写入指针为最新的指针,由此可以进行加一操作,得到目标值。
而如果不对结果为不一致,则确定数据写入指针已经发生变化,因此如果CAS操作失败,则数据写入模块需要重新从内存中读取数据写入指针和数据读取指针。
在一种可选的实施例中,Producer在CAS操作成功后,在指针的当前位置加1,得到目标存储单元的指针,结合图3所示,Producer的指针Produced加1后指向Hub:2,则Hub:2为Producer的目标存储单元。
作为一种可选的实施例,数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空,包括:数据写入模块读取目标存储单元的第二字段,判断目标存储单元的读写标识是否为第二预设值,其中,数据读取模块从目标存储单元读取数据后,将目 标存储单元的第二字段更改为第二预设值;如果目标存储单元的读写标识为第二预设值,则确定目标存储单元为空;如果目标存储单元的读写标识不为第二预设值,则确定目标存储单元不为空。
在上述方案中,为数据读取模块从存储单元中读取元素后,将存储单元第二字段更改为第二预设值,因此当数据写入模块检测到目标存储单元的第二字段的读写标识为第二预设值时,则说明数据读取模块已经将目标存储单元的元素进行了读取,当数据写入模块检测到目标存储单元的第二字段的读写标识不为第二预设值时,则说明目标存储单元中的元素还未被数据读取单元读取,因此无法写入数据。
需要说明的是,当存储队列在初始状态时,每个存储单元的第二字段的读写标识均可以设置为第二预设值。
作为一种可选的实施例,对第一预设值与二的n次方之差取反,得到第二预设值,其中,n用于表示存储队列的队列长度。
在上述方案中,第一预设值根据第二预设值确定。
在一种可选的实施例中,如果第一预设值为p,则第二预设值为~(p-2^n),其中,‘~’用于表示取反位操作。
作为一种可选的实施例,第一预设值为目标存储单元的单元标识。
具体的,目标存储单元的单元标识用于表示存储单元在存储队列中的位置,结合图3所示,对于具有2^n个存储单元的存储队列,其单元标识由0至(2^n-1),第一预设值即为目标存储单元的单元标识。
在一种可选的实施例中,结合图3所示,目标存储单元为Hub:2的存储单元,则第一预设值p=2,第二预设值为~(2-2^n)。在该示例中,当数据写入模块确定目标存储单元中第二字段的读写标识为~(2-2^n)时,则将元素写入目标存储单元,并将目标存储单元的第二字段的读写标识修改为2。
作为一种可选的实施例,存储队列所属的存储结构还包括数据写入链表,如果存储队列不存在允许插入元素的空间,则数据写入模块生成等待写入对象,并将等待写入对象插入数据写入链表。
在上述方案中,该存储结构还包括数据写入链表,用于当存储队列已满时,数据写入模块生成数据写入对象,并将数据写入对象保存在数据写入链表中,等待数据读取模块的唤醒。
在一种可选的实施例中,结合图3所示,数据写入链表为ProducerParker,支持无锁且并发安全,当Producer发现队列满时,则生成Parker,放置到ProducerParker链 表尾部,并将线程设置为闲置状态。
作为一种可选的实施例,存储队列所属的存储结构还包括数据读取链表,如果存储队列不存在允许读取的元素,则数据读取模块生成等待读取对象,并将等待读取对象插入数据读取链表。
在上述方案中,该存储结构还包括数据读取链表,用于当存储队列已空时,数据读取模块生成数据读取对象,并将数据写入对象保存在数据读取链表中,等待数据写入模块的唤醒。
在一种可选的实施例中,结合图3所示,数据写入链表为ConsumerParkers,支持无锁且并发安全,当Consumer发现队列为空时,则生成Parker,放置到ConsumerParkers链表尾部,并将线程设置为闲置状态。
上述方案基于自管理的ConsumerParkers与ProducerParkers无锁链表实现Blocking,进而降低了额Consumer或Producer在等待时的开销,提升了资源利用效率。
作为一种可选的实施例,在数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值之后,上述方法还包括:数据写入模块查找数据读取链表中是否包括等待读取对象;如果数据读取链表中包括等待读取对象,则唤醒等待读取对象对应的数据读取模块进行数据读取。
在上述方案中,数据写入模块在每次向存储队列写入元素之后,都可以检查数据读取链表中是否有等待的数据读取对象,并在数据读取链表中存在数据读取对象时,将该数据读取对象唤醒,由数据读取对象对应的数据读取模块来读取队列中的元素。
图4是根据本申请实施例1的一种数据写入模块向存储队列写入元素的示意图,下面结合图4对上述实施例中的数据的读写方法进行说明。
S51,Producer读取Produced与Consumed指针,并判断Produced与Consumed的差值是否小于队列长度,如果Produced与Consumed的差值小于队列长度,则进入步骤S52,否则进入步骤S56。
在上述步骤中,如果Produced与Consumed的差值小于队列长度,则说明队列有空间可以插入元素,否则,说明队列已经没有空间。
S52,Producer通过CAS操作将Produced指针加1,得到的值为p。如果CAS操作失败,则返回步骤S51,否则继续执行步骤S53。
S53,Producer将p所对应的Hub取出。并以spin的方式等待直到Hub中code字段的值改变成为~(p-2^n)。(‘~’是取反位操作)。
上述步骤用于确定Hub中当元素已被Consumed读取,Hub的状态为空,允许Producer 写入元素。
S54,Producer将Hub中value字段的值设置为被插入的元素。并将code字段修改为p。
S55,Producer检查ConsuemrParkers链表,如检测到ConsuemrParkers链表中存在等待的Parker,则将ConsumerParks中的第一个Parker取出并唤醒其中线程。
S56,Producer生成一个Parker对象,并将其插入ProducerParkers链表队尾,等待Consumer唤醒。当Producer被唤醒后,返回步骤S51继续执行。
需要说明的是,在高并发情况下多线程并行运行,各个线程间的指令运行顺序是无法保证的,因此可能会出现如下两种乱序冲突的情况:a)Producer与Consumer对同一个指针值的Hub的访问存在乱序冲突。原因是在多线程运行的程序中,各个线程间的指令运行顺序是无法保证的,Consumer可能先于Producer访问Hub,Producer没有修改Hub.value时,Consumer访问Hub会取不到元素。b)相差倍数为2^n的线程,可能会乱序访问同一个Hub。如图5所示,(甲)(乙)(丙)(丁)4个线程,(甲)(乙)分别需要写和读下标为2的Hub。(丙)(丁)分别需要写和读下标为18的Hub。由于数组大小为16,因此这4个线程实际访问的是同一个Hub。
本申请上述实施例中的LindormBlockingQueue使用code这一字段来解决冲突。Producer和Consumer有两条规则:1Producer必须等待code为~(p-2^n)时,才可以继续操作。操作完成后,将code修改为p;2Consumer必须等待code为c时,才可以继续操作。操作完成后,将code修改为~c。
结合图6所示,甲需要先等待code为~(-14)时,才可以写入元素,并修改code为2;
乙等待到code为2时,才读取元素,并修改为~2;
丙等待code为~2时,写入元素,并修改为18;
丁等待code为18时,读取元素,并修改为~18;
如此,则解决了上述a)和b)两类乱序冲突问题。
还需要说明的是,对于Consumed与Produced指针,Hub中的code值,均可以使用了false sharing padding技术与cacheline dirty read技术进行优化。从而进一步提高了并发能力,减少了线程间冲突。
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本发明并不受所描述的动作顺序的限制,因为依据本发明,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也 应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本发明所必须的。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例的方法。
实施例2
根据本发明实施例,还提供了一种数据的读写方法的实施例,图7是根据本申请实施例2的一种数据的读写方法的流程,如图7所示所示,该方法包括:
步骤S71,数据读取模块从存储队列中查找目标存储单元,其中,存储队列包括多个存储单元,每个存储单元包括:用于存放元素的第一字段和用于存放读写标识的第二字段。
具体的,上述数据读取模块可以是Handler。存储队列既可以是应用在分布式数据库中的阻塞队列,该队列为一个有界队列。上述读写标识是用于表征存储单元的读写状态的标识,用于数据写入模块或数据读取模块根据该标识来确定存储单元当前的读写状态。存储单元的读写状态用于表示其状态是否允许被读取或被写入元素。
数据读取模块查找目标存储单元,可以是根据队列的规则,每次确定当前的存储单元的下一个存储单元为目标存储单元。
图4是根据本申请实施例1的一种分布式数据库的阻塞队列的示意图,结合图4所示,在一种可选的实施例中,存储队列可以使用一个长度为2^n的数组作为存储结构。数组中总共有2^n个Hub(存储单元)。每个Hub由value(第一字段)与code(第二字段)两个字段构成。value用于存放数据写入模块写入的元素,code用于存放生产者与消费者模式下的访问控制标识,即上述读写标识。
步骤S73,数据读取模块根据目标存储单元的第二字段判断目标存储单元是否已被写入。
数据读取模块查找到目标存储单元后,读取目标存储单元的第二字段中的内容,并根据第二字段的内容确定目标存储单元是否已被写入元素。仍以Hub包括value与code为例,数据读取模块取出目标Hub,并读取Hub的code字段,根据Hub的code字段来 确定目标单元是否已被写入元素。
在一种可选的实施例中,code中的内容可以为A或B两种。code值为A表示Hub为空,code值为B表示Hub已被写入元素。数据读取模块读取Hub的code值后,判断其是否为B,从而可以确定该Hub是否已被写入元素。
步骤S75,在目标存储单元已被写入元素的情况下,数据读取模块读取目标存储单元内的元素,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元为空。
在上述步骤中,仅当数据读取模块确定目标存储单元已被写入元素的情况下,从存储单元中读取元素。如果目标存储单元不为空,则数据读取模块可以确定新的目标存储单元,并进入确定新的目标存储单元是否被写入元素的步骤,直至查找到为空的存储单元。
在数据读取模块从目标存储单元中读取元素后,该目标存储单元的状态已经发生变更,因此数据读取模块还需要更改目标存储单元的第二字段中的读写标识,以更改目标存储单元的状态。
在一种可选的实施例中,结合图4所示,仍以code值为A表示Hub为空,code值为B表示Hub已被写入元素为例。Consumer(数据读取模块)检测目标Hub的code值是否为B,如果目标Hub的code值为B,则确定目标Hub已被写入元素,因此Consumer从Hub的value中读取元素,并该Hub的code值更改为A。
需要说明的是,如果一个存储单元被写入了元素,但在数据读取模块读取该存储单元中的元素之前,数据写入模块确定了该存储单元为目标存储单元,则数据写入模块对其第二字段进行检测即可确定目标存储单元不为空,因此数据写入模块会重新查找新的目标存储单元,从而避免了乱序冲突。
本申请实施例中的存储单元中包括用于存储元素的字段和用于存储读写标识的字段,在数据读取模块读取存储队列存储单元中的元素之前,通过存储单元的读写标识确定该单元是否包括已写入的元素,从而确定是否访问该存储单元以从中读取元素,进而可以避免数据写入模块还未向存储单元写入元素,数据读取模块就先于数据写入模块访问存储单元所导致的乱序冲突的问题,进而提高并发效率。
由此,本申请上述实施例解决了JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的技术问题。
作为一种可选的实施例,在数据读取模块从存储队列中查找目标存储单元之前,上述方法还包括:数据读取模块判断存储队列是否存在允许读取的元素;如果存储队列存在允许读取的元素,则进入数据读取模块读取目标存储单元内的元素的步骤。
当存储队列为空时,不允许数据读取模块继续读取,因此数据读取模块在查找目标存储模块之前,还需要存储队列是否为空。
在一种可选的实施例中,Consumer在接收到数据读取任务后,首先判断存储队列是否为空,如果存储队列为空,则不存在允许读取元素的空间,如果存储队列不为空,则确定存在允许读取元素的空间。
作为一种可选的实施例,数据读取模块判断存储队列是否存在允许读取的元素,包括:数据读取模块读取数据写入指针的当前值和数据读取指针的当前值;数据读取模块获取数据写入指针的当前值和数据读取指针的当前值之间的差值;如果差值大于零,则确定存储队列存在允许读取的元素;如果差值等于存储队列的队列长度,则确定存储队列不存在允许读取的元素。
在上述方案中,数据写入模块具有对应的数据写入指针,数据读取模块具有对应的数据读取指针。数据写入指针指向数据写入模块将元素放入存储队列的最后一个存储单元,而数据读取指针指向数据读取模块将元素取出存储队列的最后一个存储单元。两个指针的值均可以为long型并单调递增。数据写入模块仅修改数据写入指针,数据读取模块仅修改数据读取指针。
数据写入模块可以从缓存中获取数据写入指针和数据读取指针,并通过与位运算确定数据写入指针与数据读取指针所指向的存储单元,与对队列的长度取模相比,与位运算即为确定指针在存储队列中的偏移量,运算消耗较小,进而能够加速运算过程。
在一种可选的实施例中,数据写入指针为Produced指针,数据读取指针为Consumed指针,存储队列的队列长度为2^n。在Producer确定目标存储单元前,现读取Produced指针和Consumed指针的差值。如果Produced指针和Consumed指针的差值大于零,则确定存在允许读取的元素,如果Produced指针和Consumed指针的差值等于=0,则确定不存在允许读取的元素。
作为一种可选的实施例,其特征在于,数据读取模块从存储队列中查找目标存储单元,包括:数据读取模块通过比较并交换操作,在数据读取指针的当前值的基础上加一,得到目标值;数据读取模块确定目标值在存储队列中所指示的存储单元为目标存储单元。
比较并交换操作为CAS操作,在上述方案中,数据是无锁的,因此需要进行CAS操作来确保数据读取模块获取的指针是最新的指针。具体的,本申请上述的比较并操作过程可以是,数据读取模块从缓存中获取数据写入指针和数据读取指针后,将从缓存中获取的数据读取指针与内存中的数据读取指针进行比对,由于内存中保存的是最新的指针,因此如果比对结果为一致,则可以确定数据读取模块从缓存获取的数据读取指针为最新的指针,由此可以进行加一操作,得到目标值。
而如果不对结果为不一致,则确定数据读取指针已经发生变化,因此如果CAS操作失败,则数据读取模块需要重新从内存中读取数据写入指针和数据读取指针。
在一种可选的实施例中,Producer在CAS操作成功后,在指针的当前位置加1,得到目标存储单元的指针,结合图4所示,Consumer的指针Consumed加1后指向Hub:1,则Hub:1为Producer的目标存储单元。
作为一种可选的实施例,数据读取模块根据目标存储单元的第二字段判断目标存储单元是否已被写入,包括:数据读取模块读取目标存储单元的第二字段,判断目标存储单元的读写标识是否为第二预设值,其中,数据写入模块将元素写入目标存储单元后,将目标存储单元的第二字段更改为第二预设值;如果目标存储单元的读写标识为第二预设值,则确定目标存储单元已被写入;如果目标存储单元的读写标识不为第二预设值,则确定目标存储单元未被写入。
数据写入模块读取目标存储单元的第二字段,判断目标存储单元的读写标识是否为第二预设值,其中,数据读取模块从目标存储单元读取数据后,将目标存储单元的第二字段更改为第二预设值;
如果目标存储单元的读写标识为第二预设值,则确定目标存储单元为空;
如果目标存储单元的读写标识不为第二预设值,则确定目标存储单元不为空。
在上述方案中,为数据写入模块向存储单元写入元素后,将存储单元第二字段更改为第二预设值,因此当数据读取模块检测到目标存储单元的第二字段的读写标识为第二预设值时,则说明数据写入模块已经向目标存储单元写入了元素,当数据读取模块检测到目标存储单元的第二字段的读写标识不为第二预设值时,则说明目标存储单元还未被写入元素,因此无法进行读取。
作为一种可选的实施例,对第一预设值与第二预设值互为相反数。
在一种可选的实施例中,如果第一预设值为c,则第二预设值为~c,其中,‘~’用于表示取反位操作。
作为一种可选的实施例,第二预设值为目标存储单元的单元标识。
具体的,目标存储单元的单元标识用于表示存储单元在存储队列中的位置,结合图4所示,对于具有2^n个存储单元的存储队列,其单元标识由0至(2^n-1),第一预设值即为目标存储单元的单元标识。
在一种可选的实施例中,结合图4所示,目标存储单元为Hub:1的存储单元,则第一预设值p=-1,第二预设值为1。在该示例中,当数据读取单元确定目标存储单元中第二字段的读写标识为1时,读取目标存储单元中的元素,并将目标存储单元的第二字段 的读写标识修改为-1。
作为一种可选的实施例,存储队列所属的存储结构还包括数据读取链表,如果存储队列不存在允许读取的元素,则数据读取模块生成等待读取对象,并将等待读取对象插入数据读取链表。
在上述方案中,该存储结构包括数据读取链表,用于当存储队列已空时,数据读取模块生成数据读取对象,并将数据写入对象保存在数据读取链表中,等待数据写入模块的唤醒。
在一种可选的实施例中,结合图4所示,数据写入链表为ConsumerParkers,支持无锁且并发安全,当Consumer发现队列为空时,则生成Parker,放置到ConsumerParkers链表尾部,并将线程设置为闲置状态。
作为一种可选的实施例,存储队列所属的存储结构还包括数据写入链表,如果存储队列不存在允许插入元素的空间,则数据写入模块生成等待写入对象,并将等待写入对象插入数据写入链表。
在上述方案中,该存储结构还包括数据写入链表,用于当存储队列已满时,数据写入模块生成数据写入对象,并将数据写入对象保存在数据写入链表中,等待数据读取模块的唤醒。
在一种可选的实施例中,结合图4所示,数据写入链表为ProducerParker,支持无锁且并发安全,当Producer发现队列满时,则生成Parker,放置到ProducerParker链表尾部,并将线程设置为闲置状态。
作为一种可选的实施例,在数据读取模块读取目标存储单元内的元素,并将目标存储单元的第二字段更改为第一预设值之后,上述方法还包括:数据读取模块查找数据写入链表中是否包括等待写入对象;如果数据写入链表中包括等待写入对象,则唤醒等待写入对象对应的数据写入模块进行数据写入。
在上述方案中,数据读取模块在每次从存储队列读取元素之后,都可以检查数据写入链表中是否有等待写入的数据写入对象,并在数据写入链表中存在数据写入对象时,将该数据写入对象唤醒,由数据写入对象对应的数据写入模块将元素写入存储队列中。
图8是根据本申请实施例2的一种数据读取模块读取存储队列元素的示意图,下面结合图8对上述实施例中的数据的读写方法进行说明。
S81,Consumer读取Produced与Consumed指针,并判断Produced与Consumed的差值是否大于0,Produced与Consumed的差值大于0,则进入步骤S82,否则进入步骤S86。
在上述步骤中,如果Produced与Consumed的差值大于0,则说明队列中有元素可以获取,否则,说明队列已经没有剩余元素。
S82,Consumer尝试通过CAS操作,将Consumed指针加1,得到的值为c。如果CAS操作失败,则返回步骤S81,否则继续执行步骤S83。
S83,Consumer将c所对应的Hub取出。并以spin的方式等待直到Hub中code字段的值改变成为c。
S84,Consumer将Hub中value字段的值设置为空,并将code字段修改为~c。
S85,Consumer检查ProducerParkers链表,如检测到ProducerParkers链表有Parker,则将ProducerParkers中的第一个Parker取出并唤醒其中线程。
S86,Consumer生成一个Parker对象,并将其插入ConsumerParkers链表队尾,等待Producer唤醒。当Consuemr被唤醒后,返回步骤S81继续执行。
实施例3
根据本发明实施例,还提供了一种用于实施实施例1中的数据的读写方法的数据的读写装置,图9是根据本申请实施例3的一种数据的读写装置的示意图,如图9所示,该装置900包括:
查找模块902,用于数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段。
判断模块904,用于数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空。
写入模块906,用于在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
此处需要说明的是,上述查找模块902、查找模块102对应于实施例1中的步骤S21至步骤S25,两个模块与对应的步骤所实现的实例和应用场景相同,但不限于上述实施例一所公开的内容。需要说明的是,上述模块作为装置的一部分可以运行在实施例一提供的计算机终端10中。
作为一种可选的实施例,上述装置还包括:确定模块,用于在数据写入模块从存储队列中查找目标存储单元之前,数据写入模块判断存储队列是否存在允许插入元素的空间;进入模块,用于如果存储队列存在允许插入元素的空间,则进入数据写入模块从存储队列中查找目标存储单元的步骤。
作为一种可选的实施例,确定模块包括:第一获取子模块,用于数据写入模块读取数据写入指针的当前值和数据读取指针的当前值;第二获取子模块,用于数据写入模块获取数据写入指针的当前值和数据读取指针的当前值之间的差值;比对子模块,用于数据写入模块将差值与存储队列的队列长度进行比对;第一确定子模块,用于如果差值小于队列长度,则确定存储队列存在允许插入元素的空间;第二确定子模块,用于如果差值等于存储队列的队列长度,则确定存储队列不存在允许插入元素的空间。
作为一种可选的实施例,查找模块包括:操作子模块,用于数据写入模块通过比较并交换操作,在数据写入指针的当前值的基础上加一,得到目标值;第三确定子模块,用于数据写入模块确定目标值在存储队列中所指示的存储单元为目标存储单元。
作为一种可选的实施例,判断模块包括:判断子模块,用于数据写入模块读取目标存储单元的第二字段,判断目标存储单元的读写标识是否为第二预设值,其中,数据读取模块从目标存储单元读取数据后,将目标存储单元的第二字段更改为第二预设值;第四确定子模块,用于如果目标存储单元的读写标识为第二预设值,则确定目标存储单元为空;第五确定子模块,用于如果目标存储单元的读写标识不为第二预设值,则确定目标存储单元不为空。
作为一种可选的实施例,对第一预设值与二的n次方之差取反,得到第二预设值,其中,n用于表示存储队列的队列长度。
作为一种可选的实施例,第一预设值为目标存储单元的单元标识。
作为一种可选的实施例,存储队列所属的存储结构还包括数据写入链表,如果存储队列不存在允许插入元素的空间,则数据写入模块生成等待写入对象,并将等待写入对象插入数据写入链表。
作为一种可选的实施例,存储队列所属的存储结构还包括数据读取链表,如果存储队列不存在允许读取的元素,则数据读取模块生成等待读取对象,并将等待读取对象插入数据读取链表。
作为一种可选的实施例,上述装置还包括:再次查找模块,用于在数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值之后,数据写入模块查找数据读取链表中是否包括等待读取对象;唤醒模块,用于如果数据读取链表中包括等待读取对象,则唤醒等待读取对象对应的数据读取模块进行数据读取。
实施例4
根据本发明实施例,还提供了一种用于实施实施例2中的数据的读写方法的数据的读写装置,图10是根据本申请实施例4的一种数据的读写装置的示意图,如图10所示, 该装置100包括:
查找模块102,用于数据读取模块从存储队列中查找目标存储单元,其中,存储队列包括多个存储单元,每个存储单元包括:用于存放元素的第一字段和用于存放读写标识的第二字段。
判断模块104,用于数据读取模块根据目标存储单元的第二字段判断目标存储单元是否已被写入。
读取模块106,用于在目标存储单元已被写入元素的情况下,数据读取模块读取目标存储单元内的元素,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元为空。
此处需要说明的是,上述查找模块102、判断模块104和读取模块106对应于实施例2中的步骤S71至步骤S75,两个模块与对应的步骤所实现的实例和应用场景相同,但不限于上述实施例一所公开的内容。需要说明的是,上述模块作为装置的一部分可以运行在实施例一提供的计算机终端10中。
作为一种可选的实施例,上述装置还包括:确定模块,用于在数据读取模块从存储队列中查找目标存储单元之前,数据读取模块判断存储队列是否存在允许读取的元素;进入模块,用于如果存储队列存在允许读取的元素,则进入数据读取模块读取目标存储单元内的元素的步骤。
作为一种可选的实施例,确定模块包括:第一获取子模块,用于数据读取模块读取数据写入指针的当前值和数据读取指针的当前值;第二获取子模块,用于数据读取模块获取数据写入指针的当前值和数据读取指针的当前值之间的差值;第一确定子模块,用于如果差值大于零,则确定存储队列存在允许读取的元素;第二确定子模块,用于如果差值等于存储队列的队列长度,则确定存储队列不存在允许读取的元素。
作为一种可选的实施例,查找模块包括:操作子模块,用于数据读取模块通过比较并交换操作,在数据读取指针的当前值的基础上加一,得到目标值;第三确定子模块,用于数据读取模块确定目标值在存储队列中所指示的存储单元为目标存储单元。
作为一种可选的实施例,判断模块包括:判断子模块,用于数据读取模块读取目标存储单元的第二字段,判断目标存储单元的读写标识是否为第二预设值,其中,数据写入模块将元素写入目标存储单元后,将目标存储单元的第二字段更改为第二预设值;第四确定子模块,用于如果目标存储单元的读写标识为第二预设值,则确定目标存储单元已被写入;第五确定子模块,用于如果目标存储单元的读写标识不为第二预设值,则确定目标存储单元未被写入。
作为一种可选的实施例,对第一预设值与第二预设值互为相反数。
作为一种可选的实施例,第二预设值为目标存储单元的单元标识。
作为一种可选的实施例,存储队列所属的存储结构还包括数据读取链表,如果存储队列不存在允许读取的元素,则数据读取模块生成等待读取对象,并将等待读取对象插入数据读取链表。
作为一种可选的实施例,存储队列所属的存储结构还包括数据写入链表,如果存储队列不存在允许插入元素的空间,则数据写入模块生成等待写入对象,并将等待写入对象插入数据写入链表。
作为一种可选的实施例,上述装置还包括:再次查找模块,用于在数据读取模块读取目标存储单元内的元素,并将目标存储单元的第二字段更改为第一预设值之后,数据读取模块查找数据写入链表中是否包括等待写入对象;唤醒模块,用于如果数据写入链表中包括等待写入对象,则唤醒等待写入对象对应的数据写入模块进行数据写入。
实施例5
本发明的实施例可以提供一种计算机终端,该计算机终端可以是计算机终端群中的任意一个计算机终端设备。可选地,在本实施例中,上述计算机终端也可以替换为移动终端等终端设备。
可选地,在本实施例中,上述计算机终端可以位于计算机网络的多个网络设备中的至少一个网络设备。
在本实施例中,上述计算机终端可以执行数据的读写方法中以下步骤的程序代码:数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空;在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
可选地,图11是根据本发明实施例5的一种计算机终端的结构框图。如图11所示,该计算机终端A可以包括:一个或多个(图中仅示出一个)处理器1102、存储器1104、以及外设接口1106。
其中,存储器可用于存储软件程序以及模块,如本发明实施例中的数据的读写方法和装置对应的程序指令/模块,处理器通过运行存储在存储器内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述的数据的读写方法。存储器可包括高速随机存储器,还可以包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器可进一步包括相对于处理器远程设置 的存储器,这些远程存储器可以通过网络连接至终端A。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
处理器可以通过传输装置调用存储器存储的信息及应用程序,以执行下述步骤:数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空;在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
可选的,上述处理器还可以执行如下步骤的程序代码:在数据写入模块从存储队列中查找目标存储单元之前,数据写入模块判断存储队列是否存在允许插入元素的空间;如果存储队列存在允许插入元素的空间,则进入数据写入模块从存储队列中查找目标存储单元的步骤。
可选的,上述处理器还可以执行如下步骤的程序代码:数据写入模块读取数据写入指针的当前值和数据读取指针的当前值;数据写入模块获取数据写入指针的当前值和数据读取指针的当前值之间的差值;数据写入模块将差值与存储队列的队列长度进行比对;如果差值小于队列长度,则确定存储队列存在允许插入元素的空间;如果差值等于存储队列的队列长度,则确定存储队列不存在允许插入元素的空间。
可选的,上述处理器还可以执行如下步骤的程序代码:数据写入模块通过比较并交换操作,在数据写入指针的当前值的基础上加一,得到目标值;数据写入模块确定目标值在存储队列中所指示的存储单元为目标存储单元。
可选的,上述处理器还可以执行如下步骤的程序代码:数据写入模块读取目标存储单元的第二字段,判断目标存储单元的读写标识是否为第二预设值,其中,数据读取模块从目标存储单元读取数据后,将目标存储单元的第二字段更改为第二预设值;如果目标存储单元的读写标识为第二预设值,则确定目标存储单元为空;如果目标存储单元的读写标识不为第二预设值,则确定目标存储单元不为空。
可选的,对第一预设值与二的n次方之差取反,得到第二预设值,其中,n用于表示存储队列的队列长度。
可选的,第一预设值为目标存储单元的单元标识。
可选的,存储队列所属的存储结构还包括数据写入链表,如果存储队列不存在允许插入元素的空间,则数据写入模块生成等待写入对象,并将等待写入对象插入数据写入链表。
可选的,存储队列所属的存储结构还包括数据读取链表,如果存储队列不存在允许读取的元素,则数据读取模块生成等待读取对象,并将等待读取对象插入数据读取链表。
可选的,上述处理器还可以执行如下步骤的程序代码:在数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储单元的第二字段更改为第一预设值之后,数据写入模块查找数据读取链表中是否包括等待读取对象;如果数据读取链表中包括等待读取对象,则唤醒等待读取对象对应的数据读取模块进行数据读取。
采用本发明实施例,提供了一种数据的读写方法的方案。本申请实施例中的存储单元中包括用于存储元素的字段和用于存储读写标识的字段,在数据写入模块向存储队列的存储单元中写入元素之前,通过存储单元的读写标识确定该单元是否为空,从而确定是否访问该存储单元以向其写入元素,进而可以避免数据读取模块还未从存储单元读取元素,数据写入模块就先于数据读取模块访问存储单元所导致的乱序冲突的情况,解决了JDK自带的阻塞队列在高并发的情况下容易发生乱序冲突,导致并发效率较低的技术问题,提高了并发效率。
本领域普通技术人员可以理解,图11所示的结构仅为示意,计算机终端也可以是智能手机(如Android手机、iOS手机等)、平板电脑、掌声电脑以及移动互联网设备(Mobile Internet Devices,MID)、PAD等终端设备。图11其并不对上述电子装置的结构造成限定。例如,计算机终端A还可包括比图11中所示更多或者更少的组件(如网络接口、显示装置等),或者具有与图11所示不同的配置。
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令终端设备相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:闪存盘、只读存储器(Read-Only Memory,ROM)、随机存取器(Random Access Memory,RAM)、磁盘或光盘等。
实施例6
本发明的实施例还提供了一种存储介质。可选地,在本实施例中,上述存储介质可以用于保存上述实施例一所提供的数据的读写方法所执行的程序代码。
可选地,在本实施例中,上述存储介质可以位于计算机网络中计算机终端群中的任意一个计算机终端中,或者位于移动终端群中的任意一个移动终端中。
可选地,在本实施例中,存储介质被设置为存储用于执行以下步骤的程序代码:数据写入模块从存储队列中查找到目标存储单元,其中,存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;数据写入模块根据目标存储单元的第二字段判断目标存储单元是否为空;在目标存储单元为空的情况下,数据写入模块将待写入元素写入目标存储单元的第一字段,并将目标存储 单元的第二字段更改为第一预设值,其中,第一预设值用于表示目标存储单元已被写入元素。
上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。
在本发明的上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。
在本申请所提供的几个实施例中,应该理解到,所揭露的技术内容,可通过其它的方式实现。其中,以上所描述的装置实施例仅仅是示意性的,例如所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,单元或模块的间接耦合或通信连接,可以是电性或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本发明的保护范围。

Claims (24)

  1. 一种数据的读写方法,其特征在于,包括:
    数据写入模块从存储队列中查找到目标存储单元,其中,所述存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;
    所述数据写入模块根据所述目标存储单元的第二字段判断所述目标存储单元是否为空;
    在所述目标存储单元为空的情况下,所述数据写入模块将待写入元素写入所述目标存储单元的第一字段,并将所述目标存储单元的第二字段更改为第一预设值,其中,所述第一预设值用于表示所述目标存储单元已被写入元素。
  2. 根据权利要求1所述的方法,其特征在于,在所述数据写入模块从存储队列中查找目标存储单元之前,所述方法还包括:
    所述数据写入模块判断所述存储队列是否存在允许插入元素的空间;
    如果所述存储队列存在允许插入元素的空间,则进入所述数据写入模块从存储队列中查找目标存储单元的步骤。
  3. 根据权利要求2所述的方法,其特征在于,所述数据写入模块判断所述存储队列是否存在允许插入元素的空间,包括:
    所述数据写入模块读取数据写入指针的当前值和数据读取指针的当前值;
    所述数据写入模块获取所述数据写入指针的当前值和数据读取指针的当前值之间的差值;
    所述数据写入模块将所述差值与所述存储队列的队列长度进行比对;
    如果所述差值小于所述队列长度,则确定所述存储队列存在允许插入元素的空间;
    如果所述差值等于所述存储队列的队列长度,则确定所述存储队列不存在允许插入元素的空间。
  4. 根据权利要求3所述的方法,其特征在于,数据写入模块从存储队列中查找目标存储单元,包括:
    所述数据写入模块通过比较并交换操作,在所述数据写入指针的当前值的基础上加一,得到目标值;
    所述数据写入模块确定所述目标值在存储队列中所指示的存储单元为所述目标存储单元。
  5. 根据权利要求1所述的方法,其特征在于,所述数据写入模块根据所述目标存储单元的第二字段判断所述目标存储单元是否为空,包括:
    所述数据写入模块读取所述目标存储单元的第二字段,判断所述目标存储单元的读写标识是否为第二预设值,其中,数据读取模块从所述目标存储单元读取数据后,将所述目标存储单元的第二字段更改为所述第二预设值;
    如果所述目标存储单元的读写标识为所述第二预设值,则确定所述目标存储单元为空;
    如果所述目标存储单元的读写标识不为所述第二预设值,则确定所述目标存储单元不为空。
  6. 根据权利要求5所述的方法,其特征在于,对所述第一预设值与二的n次方之差取反,得到所述第二预设值,其中,n用于表示所述存储队列的队列长度。
  7. 根据权利要求6所述的方法,其特征在于,所述第一预设值为所述目标存储单元的单元标识。
  8. 根据权利要求2所述的方法,其特征在于,所述存储队列所属的存储结构还包括数据写入链表,如果所述存储队列不存在允许插入元素的空间,则所述数据写入模块生成等待写入对象,并将所述等待写入对象插入所述数据写入链表。
  9. 根据权利要求1所述的方法,其特征在于,所述存储队列所属的存储结构还包括数据读取链表,如果所述存储队列不存在允许读取的元素,则数据读取模块生成等待读取对象,并将所述等待读取对象插入所述数据读取链表。
  10. 根据权利要求9所述的方法,其特征在于,在所述数据写入模块将待写入元素写入所述目标存储单元的第一字段,并将所述目标存储单元的第二字段更改为第一预设值之后,所述方法还包括:
    所述数据写入模块查找所述数据读取链表中是否包括所述等待读取对象;
    如果所述数据读取链表中包括所述等待读取对象,则唤醒所述等待读取对象对应的数据读取模块进行数据读取。
  11. 一种数据的读写方法,其特征在于,包括:
    数据读取模块从存储队列中查找目标存储单元,其中,所述存储队列包括多个存储单元,每个存储单元包括:用于存放元素的第一字段和用于存放读写标识的第二字段;
    所述数据读取模块根据所述目标存储单元的第二字段判断所述目标存储单元是否已被写入;
    在所述目标存储单元已被写入元素的情况下,所述数据读取模块读取所述目标存储单元内的元素,并将所述目标存储单元的第二字段更改为第一预设值,其中,所述第一预设值用于表示所述目标存储单元为空。
  12. 根据权利要求11所述的方法,其特征在于,在所述数据读取模块从存储队列中查找目标存储单元之前,所述方法还包括:
    所述数据读取模块判断所述存储队列是否存在允许读取的元素;
    如果所述存储队列存在允许读取的元素,则进入所述数据读取模块读取所述目标存储单元内的元素的步骤。
  13. 根据权利要求12所述的方法,其特征在于,所述数据读取模块判断所述存储队列是否存在允许读取的元素,包括:
    所述数据读取模块读取数据写入指针的当前值和数据读取指针的当前值;
    所述数据读取模块获取所述数据写入指针的当前值和数据读取指针的当前值之间的差值;
    如果所述差值大于零,则确定所述存储队列存在允许读取的元素;
    如果所述差值等于所述存储队列的队列长度,则确定所述存储队列不存在允许读取的元素。
  14. 根据权利要求13所述的方法,其特征在于,数据读取模块从存储队列中查找目标存储单元,包括:
    所述数据读取模块通过比较并交换操作,在所述数据读取指针的当前值的基础上加一,得到目标值;
    所述数据读取模块确定所述目标值在存储队列中所指示的存储单元为所述目标存储单元。
  15. 根据权利要求11所述的方法,其特征在于,所述数据读取模块根据所述目标存储单元的第二字段判断所述目标存储单元是否已被写入,包括:
    所述数据读取模块读取所述目标存储单元的第二字段,判断所述目标存储单元的读写标识是否为第二预设值,其中,数据写入模块将元素写入所述目标存储单元后,将所述目标存储单元的第二字段更改为所述第二预设值;
    如果所述目标存储单元的读写标识为所述第二预设值,则确定所述目标存储单元已被写入;
    如果所述目标存储单元的读写标识不为所述第二预设值,则确定所述目标存储单元 未被写入。
  16. 根据权利要求15所述的方法,其特征在于,对所述第一预设值与所述第二预设值互为相反数。
  17. 根据权利要求16所述的方法,其特征在于,所述第二预设值为所述目标存储单元的单元标识。
  18. 根据权利要求12所述的方法,其特征在于,所述存储队列所属的存储结构还包括数据读取链表,如果所述存储队列不存在允许读取的元素,则所述数据读取模块生成等待读取对象,并将所述等待读取对象插入所述数据读取链表。
  19. 根据权利要求11所述的方法,其特征在于,所述存储队列所属的存储结构还包括数据写入链表,如果所述存储队列不存在允许插入元素的空间,则数据写入模块生成等待写入对象,并将所述等待写入对象插入所述数据写入链表。
  20. 根据权利要求19所述的方法,其特征在于,在所述数据读取模块读取所述目标存储单元内的元素,并将所述目标存储单元的第二字段更改为第一预设值之后,所述方法还包括:
    所述数据读取模块查找所述数据写入链表中是否包括所述等待写入对象;
    如果所述数据写入链表中包括所述等待写入对象,则唤醒所述等待写入对象对应的数据写入模块进行数据写入。
  21. 一种数据的读写装置,其特征在于,包括:
    查找模块,用于数据写入模块从存储队列中查找到目标存储单元,其中,所述存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;
    判断模块,用于所述数据写入模块根据所述目标存储单元的第二字段判断所述目标存储单元是否为空;
    写入模块,用于在所述目标存储单元为空的情况下,所述数据写入模块将待写入元素写入所述目标存储单元的第一字段,并将所述目标存储单元的第二字段更改为第一预设值,其中,所述第一预设值用于表示所述目标存储单元已被写入元素。
  22. 一种数据的读写装置,其特征在于,包括:
    查找模块,用于数据读取模块从存储队列中查找目标存储单元,其中,所述存储队列包括多个存储单元,每个存储单元包括:用于存放元素的第一字段和用于存放读写标识的第二字段;
    判断模块,用于所述数据读取模块根据所述目标存储单元的第二字段判断所述目标存储单元是否已被写入;
    写入模块,用于在所述目标存储单元已被写入元素的情况下,所述数据读取模块读取所述目标存储单元内的元素,并将所述目标存储单元的第二字段更改为第一预设值,其中,所述第一预设值用于表示所述目标存储单元为空。
  23. 一种存储介质,其特征在于,所述存储介质包括存储的程序,其中,在所述程序运行时控制所述存储介质所在设备执行如下步骤:数据写入模块从存储队列中查找到目标存储单元,其中,所述存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;所述数据写入模块根据所述目标存储单元的第二字段判断所述目标存储单元是否为空;在所述目标存储单元为空的情况下,所述数据写入模块将待写入元素写入所述目标存储单元的第一字段,并将所述目标存储单元的第二字段更改为第一预设值,其中,所述第一预设值用于表示所述目标存储单元已被写入元素。
  24. 一种处理器,其特征在于,所述处理器用于运行程序,其中,所述程序运行时执行如下步骤:数据写入模块从存储队列中查找到目标存储单元,其中,所述存储队列包括多个存储单元,每个存储单元至少包括:用于存放元素的第一字段和用于存放读写标识的第二字段;所述数据写入模块根据所述目标存储单元的第二字段判断所述目标存储单元是否为空;在所述目标存储单元为空的情况下,所述数据写入模块将待写入元素写入所述目标存储单元的第一字段,并将所述目标存储单元的第二字段更改为第一预设值,其中,所述第一预设值用于表示所述目标存储单元已被写入元素。
PCT/CN2020/076106 2019-03-06 2020-02-21 数据的读写方法和装置 Ceased WO2020177549A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910168960.1A CN111666330B (zh) 2019-03-06 2019-03-06 数据的读写方法和装置
CN201910168960.1 2019-03-06

Publications (1)

Publication Number Publication Date
WO2020177549A1 true WO2020177549A1 (zh) 2020-09-10

Family

ID=72338177

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/076106 Ceased WO2020177549A1 (zh) 2019-03-06 2020-02-21 数据的读写方法和装置

Country Status (3)

Country Link
CN (1) CN111666330B (zh)
TW (1) TW202034154A (zh)
WO (1) WO2020177549A1 (zh)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113392098A (zh) * 2021-06-11 2021-09-14 北京沃东天骏信息技术有限公司 一种数据写入方法、装置、设备及存储介质
CN113672406A (zh) * 2021-08-24 2021-11-19 北京天融信网络安全技术有限公司 数据传输处理方法、装置、电子设备及存储介质
CN114296802A (zh) * 2021-12-31 2022-04-08 海光信息技术股份有限公司 指令执行控制方法、装置、处理器和电子设备
CN118828260A (zh) * 2023-09-20 2024-10-22 中国移动通信有限公司研究院 数据处理方法、装置、otn设备、电子设备和存储介质
CN119376795A (zh) * 2024-12-30 2025-01-28 北京微核芯科技有限公司 取数指令发射队列的分布式实现方法和装置

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112631957B (zh) * 2020-12-14 2024-04-05 深兰人工智能(深圳)有限公司 数据采集方法、装置、电子设备及存储介质
CN113064558B (zh) * 2021-06-04 2021-09-17 广东汇天航空航天科技有限公司 一种数据存储方法和装置
CN115270690B (zh) * 2022-09-26 2022-11-29 中科声龙科技发展(北京)有限公司 查找空闲存储的装置、方法及芯片
CN116107503A (zh) * 2022-12-26 2023-05-12 长春吉大正元信息技术股份有限公司 数据传输方法、装置及电子设备
CN116795322A (zh) * 2023-06-21 2023-09-22 广州市玄武无线科技股份有限公司 一种多标签队列实现方法、装置、电子设备及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101162608A (zh) * 2006-10-10 2008-04-16 北京华旗资讯数码科技有限公司 闪存的存储块的标识方法
CN104142979A (zh) * 2014-07-15 2014-11-12 武汉理工大学 一种实现rfid标签存储管理的索引方法
CN104281535A (zh) * 2014-09-24 2015-01-14 北京兆易创新科技股份有限公司 一种映射表在内存中的处理方法和装置
US9501407B1 (en) * 2011-09-16 2016-11-22 Altera Corporation First-in-first-out memory with dual memory banks

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9448856B2 (en) * 2005-12-30 2016-09-20 Level 3 Communications, Llc Lock-free dual queue with condition synchronization and time-outs
CN102045258B (zh) * 2010-12-22 2012-12-12 北京星网锐捷网络技术有限公司 数据缓存管理方法及装置
CN107315533A (zh) * 2016-04-26 2017-11-03 杭州海康威视数字技术股份有限公司 一种数据存储方法及装置
CN109101528A (zh) * 2018-06-21 2018-12-28 深圳市买买提信息科技有限公司 数据处理方法、数据处理装置及电子设备

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101162608A (zh) * 2006-10-10 2008-04-16 北京华旗资讯数码科技有限公司 闪存的存储块的标识方法
US9501407B1 (en) * 2011-09-16 2016-11-22 Altera Corporation First-in-first-out memory with dual memory banks
CN104142979A (zh) * 2014-07-15 2014-11-12 武汉理工大学 一种实现rfid标签存储管理的索引方法
CN104281535A (zh) * 2014-09-24 2015-01-14 北京兆易创新科技股份有限公司 一种映射表在内存中的处理方法和装置

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113392098A (zh) * 2021-06-11 2021-09-14 北京沃东天骏信息技术有限公司 一种数据写入方法、装置、设备及存储介质
CN113672406A (zh) * 2021-08-24 2021-11-19 北京天融信网络安全技术有限公司 数据传输处理方法、装置、电子设备及存储介质
CN113672406B (zh) * 2021-08-24 2024-02-06 北京天融信网络安全技术有限公司 数据传输处理方法、装置、电子设备及存储介质
CN114296802A (zh) * 2021-12-31 2022-04-08 海光信息技术股份有限公司 指令执行控制方法、装置、处理器和电子设备
CN118828260A (zh) * 2023-09-20 2024-10-22 中国移动通信有限公司研究院 数据处理方法、装置、otn设备、电子设备和存储介质
CN119376795A (zh) * 2024-12-30 2025-01-28 北京微核芯科技有限公司 取数指令发射队列的分布式实现方法和装置

Also Published As

Publication number Publication date
CN111666330B (zh) 2023-05-02
CN111666330A (zh) 2020-09-15
TW202034154A (zh) 2020-09-16

Similar Documents

Publication Publication Date Title
WO2020177549A1 (zh) 数据的读写方法和装置
EP2851807B1 (en) Method and system for supporting resource isolation under multi-core architecture
US8140828B2 (en) Handling transaction buffer overflow in multiprocessor by re-executing after waiting for peer processors to complete pending transactions and bypassing the buffer
US6170070B1 (en) Test method of cache memory of multiprocessor system
US10733101B2 (en) Processing node, computer system, and transaction conflict detection method
US20160085585A1 (en) Memory System, Method for Processing Memory Access Request and Computer System
US10331499B2 (en) Method, apparatus, and chip for implementing mutually-exclusive operation of multiple threads
CN112148477B (zh) 服务进程处理方法、电子装置及存储介质
CN113608684B (zh) 内存信息获取方法、装置、系统、电子设备及存储介质
WO2020233435A1 (zh) 数据处理方法、装置和系统
CN116521608B (zh) 数据迁移方法及计算设备
CN103297614A (zh) 一种双系统智能终端运行方法及装置
CN111709032A (zh) 一种在多种分区上实现pfr功能的方法、系统、设备及介质
CN114780248B (zh) 资源访问方法、装置、计算机设备及存储介质
US20170300255A1 (en) Method and Apparatus for Detecting Transaction Conflict and Computer System
CN103020003A (zh) 面向多核程序确定性重演的内存竞争记录装置及其控制方法
CN112698715B (zh) 一种执行控制方法、装置、嵌入式系统、设备及介质
CN103197964A (zh) 在电子装置的多个操作系统间进行信息交换的方法
CN119988302A (zh) 多核系统的数据处理方法及集群、缓存、系统
US20070055839A1 (en) Processing operation information transfer control systems and methods
US8726069B2 (en) Highly available file system in a directly attached storage
CN111381881A (zh) 一种基于ahb总线接口的低功耗指令缓存方法及装置
CN113742091B (zh) 一种线程运行方法、装置、计算机设备和存储介质
CN117176606A (zh) 智能网卡的初始化异常检测方法、系统、服务器及介质
WO2024124737A1 (zh) 异构计算中进程切换管理方法及计算装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20766712

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20766712

Country of ref document: EP

Kind code of ref document: A1