CN108572876B - Method and device for realizing read-write lock - Google Patents

Method and device for realizing read-write lock Download PDF

Info

Publication number
CN108572876B
CN108572876B CN201810186320.9A CN201810186320A CN108572876B CN 108572876 B CN108572876 B CN 108572876B CN 201810186320 A CN201810186320 A CN 201810186320A CN 108572876 B CN108572876 B CN 108572876B
Authority
CN
China
Prior art keywords
state
read
request message
write
lock
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810186320.9A
Other languages
Chinese (zh)
Other versions
CN108572876A (en
Inventor
谢正明
赵刚
董映
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhou Lvmeng Chengdu Technology Co ltd
Nsfocus Technologies Inc
Nsfocus Technologies Group Co Ltd
Original Assignee
Nsfocus Technologies Inc
Beijing NSFocus Information Security Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nsfocus Technologies Inc, Beijing NSFocus Information Security Technology Co Ltd filed Critical Nsfocus Technologies Inc
Priority to CN201810186320.9A priority Critical patent/CN108572876B/en
Publication of CN108572876A publication Critical patent/CN108572876A/en
Application granted granted Critical
Publication of CN108572876B publication Critical patent/CN108572876B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Multi Processors (AREA)

Abstract

The invention discloses a method and a device for realizing a read-write lock. The method comprises the following steps: receiving a first request message sent by a user, if the first request message is used for requesting to read data, acquiring the state of a preset read-write lock, and after determining that the state of the preset read-write lock is a first state, reading the data according to the first request message. The first state indicates that no thread writes data, and therefore, after the embodiment of the invention can directly determine that no thread writes data according to the state of the preset read-write lock, in a system with frequent read operations and relatively few write operations, the embodiment of the invention can greatly reduce the overhead of thread read-write lock, thereby avoiding the situation that each read operation needs to lock or unlock a system bus to easily cause congestion among a plurality of read operations, reducing the collision probability of locking and unlocking among a plurality of read operations, and further improving the execution efficiency of the system.

Description

Method and device for realizing read-write lock
Technical Field
The invention relates to the technical field of communication, in particular to a method and a device for realizing a read-write lock.
Background
The read-write lock is a spin lock, and divides an access user of a shared resource into a read user and a write user, wherein the read user only performs read operation on the shared resource, and the write user performs write operation on the shared resource. One read-write lock can only have one write user or a plurality of read users at the same time, but can not have both read users and write users at the same time. In a multiprocessor system, multiple read users are allowed to access a shared resource at the same time, and write operations are blocked while read operations are locked. When in write-lock, all operations attempting to read from or write to the resource will be blocked.
Currently, the read operation or the write operation is implemented by a thread, and in an operating system with a thread introduced, the thread can be used as a basic unit for independent operation and independent scheduling. Multiple threads can be executed concurrently, so that when the same data is modified, other threads can also modify the data; or, because data cannot be read due to being modified, the system bus is usually locked during a process of performing a read operation or a write operation on the data by a thread, and the system bus is unlocked after the read operation or the write operation is performed.
Therefore, a method for implementing a read/write lock is needed to solve the problem that congestion is easily generated among a plurality of read operations due to the fact that each read operation needs to be locked or unlocked on a system bus in the prior art.
Disclosure of Invention
The embodiment of the invention provides a method and a device for realizing a read-write lock, which aim to solve the technical problem that congestion is easily generated among a plurality of read operations because each read operation needs to lock or unlock a system bus in the prior art.
The embodiment of the invention provides a method for realizing a read-write lock, which comprises the following steps:
receiving a first request message sent by a user;
if the first request message is used for requesting to read data, acquiring the state of a preset read-write lock, and after determining that the state of the preset read-write lock is a first state, reading the data according to the first request message; the first state indicates that there is no thread writing the data.
Optionally, if the first request message is used to request a write operation on the data, the method further includes:
setting the state of the preset read-write lock to be a second state; the second state represents that a thread for writing the data currently exists;
and setting a system bus in a write lock state, and writing the data according to the first request message.
Optionally, after the write operation is completed on the data, the method further includes:
and setting the state of the preset read-write lock to be a first state.
Optionally, setting the state of the preset read-write lock to a first state includes:
if the second request message does not exist, setting the state of the preset read-write lock to be a first state; or if the second request message is determined to exist and the second request message is used for requesting to read data, waking up the second request message and setting the state of the preset read-write lock to be a first state;
wherein the second request message is a request message received in the process of executing the first request message.
Optionally, the method further comprises:
if the preset read-write lock state is determined to be the second state and the system bus is not determined to be in the write-add lock state, setting the system bus to be in the read-add lock state, and performing read operation on the data according to the first request message; the second state indicates that there is a thread writing data.
The embodiment of the invention provides a device for realizing a read-write lock, which comprises:
the receiving unit is used for receiving a first request message sent by a user;
the processing unit is used for acquiring the state of a preset read-write lock if the first request message is used for requesting to read data, and reading the data according to the first request message after determining that the state of the preset read-write lock is a first state; the first state indicates that there is no thread writing the data.
Optionally, the processing unit is further configured to:
if the first request message is used for requesting to write the data, setting the state of the preset read-write lock to be a second state; the second state represents that a thread for writing the data currently exists; and setting a system bus in a write lock state, and performing write operation on the data according to the first request message.
Optionally, after completing the write operation on the data, the processing unit is further configured to:
and setting the state of the preset read-write lock to be a first state.
Optionally, the processing unit is specifically configured to:
if the second request message does not exist, setting the state of the preset read-write lock to be a first state; or if the second request message is determined to exist and the second request message is used for requesting to read data, waking up the second request message and setting the state of the preset read-write lock to be a first state;
wherein the second request message is a request message received in the process of executing the first request message.
Optionally, the processing unit is further configured to:
if the preset read-write lock state is determined to be the second state and the system bus is not determined to be in the write-add lock state, setting the system bus to be in the read-add lock state, and performing read operation on the data according to the first request message; the second state indicates that there is a thread writing data.
In the embodiment of the invention, a first request message sent by a user is received, if the first request message is used for requesting to read data, the state of the preset read-write lock can be obtained, and after the state of the preset read-write lock is determined to be the first state, the data is read according to the first request message. The first state indicates that no thread is currently available for writing data, so that the embodiment of the invention can directly perform read operation on the data according to the first request message after determining that no thread is currently available for writing data according to the state of the read-write lock, and compared with the conventional read-write lock implementation mode in which read operation can be performed only after a read lock is required to be performed on a system bus, the embodiment of the invention does not need to perform the read lock on the system bus, thereby shortening the processing time of the read operation; furthermore, in a high-concurrency multiprocessor system, especially a system with frequent read operations and relatively few write operations, the method provided by the embodiment of the invention can greatly reduce the overhead of thread read lock adding, thereby avoiding the situation that each read operation needs to lock or unlock a system bus to easily cause congestion among a plurality of read operations, reducing the collision probability of lock adding and unlock among a plurality of read operations, and further improving the execution efficiency of the system.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
FIG. 1 is a schematic flow chart of a method for implementing a read/write lock provided in the prior art;
fig. 2 is a schematic flowchart of a method for implementing a read/write lock according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating another implementation method of a read/write lock according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of an overall flow involved in an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an implementation apparatus of a read-write lock according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In an operating system with threads, when a plurality of threads are executed concurrently, the same data is often required to be accessed. To ensure the integrity of this data, lock mechanisms are currently used. For example, before a thread reads a piece of data, a read lock is first applied to the data, and after the read operation is completed, the read lock is then released. Similarly, before a thread performs a write operation on a datum, the data is locked by writing, and after the execution of the read operation is finished, the lock by writing is unlocked. Further, the thread locks or unlocks the data, that is, locks or unlocks the system bus.
For convenience of understanding, fig. 1 exemplarily shows a flowchart of a method for implementing a read-write lock provided in the prior art, as shown in fig. 1, taking a thread as an example, before the thread performs a write operation on data, the thread first performs a write lock on a system bus, so that no other thread can use the bus, and at this time, a state of the system bus is obtained and analyzed to determine whether there is a thread performing a read operation or a write operation on the data. When the data is allowed to be read, the system bus needs to be locked (new read identification is calculated) first. It can be seen that, in the implementation process of the prior art, since each read operation needs to add a read lock to the system bus, in a high-concurrency multiprocessor system, especially in a system with very frequent read operations and relatively few write operations, such as a routing table and an Address Resolution Protocol (ARP) table, congestion between multiple read operations is easily caused, and thus the execution efficiency of the multiprocessor system is reduced.
In view of this, an embodiment of the present invention provides a method for implementing a read/write lock, which can directly perform a read operation on data according to a first request message after determining that no thread currently exists to perform the write operation on the data according to a state of the read/write lock, and compared with an existing read/write lock implementation mode in which a read lock needs to be performed on a system bus, the read operation in the embodiment of the present invention does not need to perform the read lock on the system bus, so that processing time of the read operation can be shortened; furthermore, in a high-concurrency multiprocessor system, especially a system with frequent read operations and relatively few write operations, the method provided by the embodiment of the invention can greatly reduce the overhead of thread read lock adding, thereby avoiding the situation that each read operation needs to lock or unlock a system bus to easily cause congestion among a plurality of read operations, reducing the collision probability of lock adding and unlock among a plurality of read operations, and further improving the execution efficiency of the system.
The technical scheme provided by the embodiment of the invention is described in the following with the accompanying drawings of the specification.
The first embodiment is as follows:
fig. 2 exemplarily shows a flowchart corresponding to the implementation method of the read-write lock according to the embodiment of the present invention, and as shown in fig. 2, the method specifically includes the following steps:
step 201, a first request message sent by a user is received.
Step 202, if the first request message is used to request a read operation on data, acquiring a state of a preset read-write lock, and after determining that the state of the preset read-write lock is a first state, performing a read operation on the data according to the first request message.
Specifically, in step 202, the preset read/write lock may be set in front of the system bus, so as to execute the corresponding operation according to the state of the preset read/write lock. In the embodiment of the present invention, the preset states of the read-write lock include a first state and a second state, where the first state indicates that there is no thread performing write operation on the data, and the second state indicates that there is a thread performing write operation on the data.
In the embodiment of the present invention, the preset state of the read/write lock may be represented in various forms, for example, in a character string form; alternatively, it can be in text form; alternatively, the numerical value may be used. Taking numerical form as an example, the status of the preset read/write lock may be expressed by setting FLAG and assigning a value to the FLAG. For example, when FLAG is set to 0, the state of the read-write lock is preset to be a first state, that is, no thread currently exists to perform write operation on the data; and when FLAG is set to 1, the state of the preset read-write lock is set to be a second state, that is, the current thread performs write operation on the data.
In the embodiment of the present invention, the executed steps are different according to different obtained preset read-write lock states, and the following description will specifically describe different preset read-write lock states.
(1) Presetting the state of the read-write lock as a first state
If the preset state of the read-write lock is the first state, it indicates that there is no thread performing write operation on the data, specifically, the two cases are included:
in case one, a thread for writing the data does not exist at present, and a thread for reading the data does not exist either;
in case two, there is currently no thread that writes to the data, but there is a thread that reads to the data.
In the second case, although there is a thread that performs a read operation on data, the read-write lock, as a spin lock, may allow multiple read users to exist, and therefore, both cases may perform a read operation on the data according to the first request message.
(2) Presetting the state of the read-write lock as a second state
And if the preset state of the read-write lock is a second state, indicating that a thread for writing the data exists currently. According to the nature of the read-write lock, one read-write lock can only have one write user or a plurality of read users at the same time, but cannot have both the read user and the write user at the same time, so that if the state of the read-write lock is preset to be the second state, the state of the system bus can be further judged.
In the embodiment of the invention, the states of the system bus comprise a write lock state and a non-write lock state. The following is a detailed description of the two different system bus states described above.
The first state: write lock status
And if the state of the system bus is the write lock state, indicating that the current thread still has write operation on the data, and the first request message needs to wait for the completion of the write operation.
And a second state: non-write lock state
And if the state of the system bus is a non-write-lock state, indicating that no thread for writing the data exists currently. That is, the write operation is completed in the time period from the determination that the state of the preset read-write lock is the second state to the determination that the state of the system bus is the non-write-locked state.
Further, the system bus may be set in a read lock state, and the data may be read according to the first request message.
In the embodiment of the present invention, a read operation does not need to lock a system bus, and in a high-concurrency multiprocessor system, especially a system with frequent read operations and relatively few write operations, the method described in the above step 201 and step 202 can greatly reduce the overhead of thread read lock, and improve the concurrency capability among multiple threads, so that a situation that each read operation needs to lock or unlock the system bus, which is likely to cause congestion among multiple read operations, can be avoided, the collision probability of lock and unlock among multiple read operations is reduced, and further, the execution efficiency of the system is improved.
Example two:
fig. 3 exemplarily shows a flowchart corresponding to another implementation method of a read-write lock according to an embodiment of the present invention, and as shown in fig. 3, the method specifically includes the following steps:
step 301, receiving a first request message sent by a user.
Step 302, if the first request message is used to request a write operation on data, setting the state of the preset read-write lock to a second state.
Step 303, setting the system bus in a write lock state, and performing write operation on the data according to the first request message.
In steps 301 and 302, after determining that the received first request message is for requesting to write data, the state of the preset read-write lock may be set to the second state, so as to avoid collision between other messages sent by the user and behind the first request message and the first request message; furthermore, the preset read-write lock state can be reset only when the first request message is used for requesting to write data, and because the write operation times are far less than the read operation times in a scene applicable to the embodiment of the invention, the method can greatly reduce the frequency of resetting the preset read-write lock state, and further improve the system operation efficiency.
In step 303, before the system bus is set to be in the write lock state, the subsequent operations may be executed after waiting for a preset time period. The preset time period can be determined according to the execution time of the read operation and can be determined according to the average execution time of a plurality of read operations; alternatively, the frequency of the read operation and the execution time of the read operation may be determined. The preset time period can be determined by a person skilled in the art according to experience and practical situations, and is not limited specifically. Therefore, the situation that the conflict between the write operation and the read operation requested by the first request message is caused by the fact that the thread performs the read operation on the data before the state of the preset read-write lock is set can be avoided.
Further, after the data is written, the state of the preset read-write lock may be set to the first state, so that the corresponding process can be conveniently executed by a subsequent request message requesting the read operation.
Specifically, after the write operation is completed on the data, before the state of the preset read-write lock is set to the first state, whether a second request message exists may be determined, where the second request message is a request message received in the process of executing the first request message. According to the judgment result, the following three cases can be classified: (1) there is no second request message; (2) the second request message exists and is used for requesting to read the data; (3) there is a second request message, and the second request message is for requesting a write operation to the data.
In the above-described case, if the first case is the case, it may be directly preset to set the state of the write lock to the first state; if the situation is the second situation, the second request message can be awakened, and the state of the preset read-write lock is set to be the first state; if the third condition is satisfied, after a preset time period, resetting the system bus to be in the write lock state, and performing a write operation on the data according to the second request message.
In the embodiment of the present invention, only when the operation requested by the request message is a write operation, the state of the read/write station is reset, and the write lock is applied to the system bus, so that compared with the case that the system bus needs to be locked regardless of the read operation or the write operation in the prior art, the method described in the above step 301 to step 303 is adopted, which can greatly reduce the overhead of thread read lock, and especially can improve the system efficiency of high concurrency and high throughput in a large server.
In order to more clearly introduce the processes described in the first and second embodiments, the processes involved in the embodiments of the present invention are collectively described below with reference to fig. 4. As shown in fig. 4, the following steps may be included:
step 401, a first request message sent by a user is received.
Step 402, judging whether the operation requested by the first request message is a read operation or a write operation, and if the operation is the read operation, executing step 403; if the operation is a write operation, step 414 is performed.
In step 403, the state of the preset read-write lock is obtained.
Step 404, determining whether the preset read-write lock state is a first state or a second state, and if the preset read-write lock state is the first state, executing step 405; if the status is the second status, go to step 406.
Step 405, performing a read operation on the data according to the first request message.
Step 406, determining whether the state of the system bus is a write lock state, and if so, executing step 407; if the status is not write-locked, step 408 is performed.
Step 407, wait until the first request message is woken up.
And step 408, adding a read lock to the system bus to enable the system bus to be in a read lock state, and performing a read operation on the data according to the first request message.
Step 409, the system bus is unlocked.
Step 410, judging whether a thread still exists for reading the data, if so, returning to the step 410; if not, go to step 411.
Step 411, determining whether there is a request message requesting to write data, if yes, executing step 412; if not, the flow ends.
Step 413, waking up the request message for requesting to write data.
Step 414, the state of the preset read-write lock is set to the second state.
Step 415, after a preset time period, setting the system bus to be in a write lock state, and performing a write operation on data according to the first request message.
At step 416, the lock is unlocked to the system bus.
Step 417, determining whether a second request message exists, where the second request message is a request message received in the process of executing the first request message, and if so, executing step 418; if not, go to step 420.
Step 418, determining whether the second request message is used for requesting to read data or to request to write data, if so, executing step 419; if the operation is a write operation, the process returns to step 415.
Step 419 waking up the second request message.
Step 420, the state of the preset read-write lock is set to the first state.
In the above steps 403 to 413, when the state of the preset read/write lock is the first state, it is not necessary to set the system bus in the read/write lock state, so that the time for setting the read/write lock can be reduced; when the preset read-write lock state is the second state, namely a thread for writing data exists, the bus state is set to be in the write-add lock state, and the overhead of adding the read lock by the thread can be greatly reduced.
In the above-mentioned steps 414 to 420, when the first request message requests a write operation, the state of the preset read/write lock needs to be set to the second state, and in order to ensure that the previous read operation is completed successfully, before setting the system bus in the write lock state, the write operation needs to be performed after waiting for a preset time period. After the write operation is completed, the state of the preset read-write lock needs to be set to the first state, so that the corresponding steps can be conveniently executed by the subsequent read-request operation.
That is to say, in the embodiment of the present invention, under the condition that the write operation is not performed, it is not necessary to set the system bus to be in the reading lock state; in the case of a write operation, the state of the set read/write lock needs to be set to the second state.
It should be noted that the step number is only an exemplary representation of an execution flow, and the sequence of each step is not specifically limited in the present application, for example, in the step 419 and the step 420, the state of the preset read/write lock may be set to be the first state, and then the second request message may be awakened.
Example three:
for the above method flow, the present application further provides a device for implementing a read/write lock, and the specific implementation of the device may refer to the above method flow, and fig. 5 exemplarily shows a schematic structural diagram of the device for implementing a read/write lock according to an embodiment of the present invention, and as shown in fig. 5, the device includes a receiving unit 501 and a processing unit 502; wherein the content of the first and second substances,
a receiving unit 501, configured to receive a first request message sent by a user;
a processing unit 502, configured to obtain a state of a preset read/write lock if the first request message is used to request a read operation on data, and perform a read operation on the data according to the first request message after determining that the state of the preset read/write lock is a first state; the first state indicates that there is no thread writing the data.
Optionally, the processing unit 502 is further configured to:
if the first request message is used for requesting to write the data, setting the state of the preset read-write lock to be a second state; the second state represents that a thread for writing the data currently exists; and setting a system bus in a write lock state, and performing write operation on the data according to the first request message.
Optionally, after completing the write operation on the data, the processing unit 502 is further configured to:
and setting the state of the preset read-write lock to be a first state.
Optionally, the processing unit 502 is specifically configured to:
if the second request message does not exist, setting the state of the preset read-write lock to be a first state; or if the second request message is determined to exist and the second request message is used for requesting to read data, waking up the second request message and setting the state of the preset read-write lock to be a first state;
wherein the second request message is a request message received in the process of executing the first request message.
Optionally, the processing unit 502 is further configured to:
if the preset read-write lock state is determined to be the second state and the system bus is not determined to be in the write-add lock state, setting the system bus to be in the read-add lock state, and reading the data according to the first request message; the second state indicates that there is a thread writing data.
In the embodiment of the invention, a first request message sent by a user is received, if the first request message is used for requesting to read data, the state of the preset read-write lock can be obtained, and after the state of the preset read-write lock is determined to be the first state, the data is read according to the first request message. The first state indicates that no thread is currently available for writing data, so that the embodiment of the invention can directly perform read operation on the data according to the first request message after determining that no thread is currently available for writing data according to the state of the read-write lock, and compared with the conventional read-write lock implementation mode in which read operation can be performed only after a read lock is required to be performed on a system bus, the embodiment of the invention does not need to perform the read lock on the system bus, thereby shortening the processing time of the read operation; furthermore, in a high-concurrency multiprocessor system, especially a system with frequent read operations and relatively few write operations, the method provided by the embodiment of the invention can greatly reduce the overhead of thread read lock adding, thereby avoiding the situation that each read operation needs to lock or unlock a system bus to easily cause congestion among a plurality of read operations, reducing the collision probability of lock adding and unlock among a plurality of read operations, and further improving the execution efficiency of the system; furthermore, by using the method provided by the embodiment of the present invention, compared with the prior art, the performance of the read operation can be improved by about 50 times, and if the method is applied to the routing table and the ARP table, the performance of the read operation in the embodiment of the present invention can be improved by 2 to 3 times compared with the performance of three-layer forwarding in the prior art.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. A method for implementing a read-write lock is characterized by comprising the following steps:
receiving a first request message sent by a user;
if the first request message is used for requesting to read data, acquiring the state of a preset read-write lock, and after determining that the state of the preset read-write lock is a first state, reading the data according to the first request message; the first state indicates that there is no thread writing the data; under the condition of not carrying out writing operation, a system bus does not need to be set to be in a reading locking state; in the case of a write operation, the state of the read-write lock needs to be set to the second state.
2. The method of claim 1, wherein if the first request message is for requesting a write operation to the data, the method further comprises:
setting the state of the preset read-write lock to be a second state; the second state represents that a thread for writing the data currently exists;
and setting a system bus in a write lock state, and writing the data according to the first request message.
3. The method of claim 2, wherein after completing a write operation on the data, the method further comprises:
and setting the state of the preset read-write lock to be a first state.
4. The method of claim 3, wherein setting the state of the preset read-write lock to the first state comprises:
if the second request message does not exist, setting the state of the preset read-write lock to be a first state; or if the second request message is determined to exist and the second request message is used for requesting to read data, waking up the second request message and setting the state of the preset read-write lock to be a first state;
wherein the second request message is a request message received in the process of executing the first request message.
5. The method of claim 1, further comprising:
if the preset read-write lock state is determined to be the second state and the system bus is not determined to be in the write-add lock state, setting the system bus to be in the read-add lock state, and performing read operation on the data according to the first request message; the second state indicates that there is a thread writing data.
6. An implementation apparatus of a read-write lock, comprising:
the receiving unit is used for receiving a first request message sent by a user;
the processing unit is used for acquiring the state of a preset read-write lock if the first request message is used for requesting to read data, and reading the data according to the first request message after determining that the state of the preset read-write lock is a first state; the first state indicates that there is no thread writing the data; under the condition of not carrying out writing operation, a system bus does not need to be set to be in a reading locking state; in the case of a write operation, the state of the read-write lock needs to be set to the second state.
7. The apparatus of claim 6, wherein the processing unit is further configured to:
if the first request message is used for requesting to write the data, setting the state of the preset read-write lock to be a second state; the second state represents that a thread for writing the data currently exists; and setting a system bus in a write lock state, and performing write operation on the data according to the first request message.
8. The apparatus of claim 7, wherein the processing unit, after completing the write operation on the data, is further to:
and setting the state of the preset read-write lock to be a first state.
9. The apparatus according to claim 8, wherein the processing unit is specifically configured to:
if the second request message does not exist, setting the state of the preset read-write lock to be a first state; or if the second request message is determined to exist and the second request message is used for requesting to read data, waking up the second request message and setting the state of the preset read-write lock to be a first state;
wherein the second request message is a request message received in the process of executing the first request message.
10. The apparatus of claim 6, wherein the processing unit is further configured to:
if the preset read-write lock state is determined to be the second state and the system bus is not determined to be in the write-add lock state, setting the system bus to be in the read-add lock state, and performing read operation on the data according to the first request message; the second state indicates that there is a thread writing data.
CN201810186320.9A 2018-03-07 2018-03-07 Method and device for realizing read-write lock Active CN108572876B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810186320.9A CN108572876B (en) 2018-03-07 2018-03-07 Method and device for realizing read-write lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810186320.9A CN108572876B (en) 2018-03-07 2018-03-07 Method and device for realizing read-write lock

Publications (2)

Publication Number Publication Date
CN108572876A CN108572876A (en) 2018-09-25
CN108572876B true CN108572876B (en) 2020-11-20

Family

ID=63576762

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810186320.9A Active CN108572876B (en) 2018-03-07 2018-03-07 Method and device for realizing read-write lock

Country Status (1)

Country Link
CN (1) CN108572876B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111104412B (en) * 2018-10-25 2023-05-30 阿里巴巴集团控股有限公司 Concurrent control method, device and system based on single thread
CN109698971B (en) * 2019-01-15 2021-07-06 海信视像科技股份有限公司 Data processing method and device
CN111857545B (en) * 2019-04-28 2023-12-29 深信服科技股份有限公司 Read-write lock conflict judging method, system, equipment and computer medium
CN110908968B (en) * 2019-11-14 2022-05-27 浪潮电子信息产业股份有限公司 Method, device, equipment and storage medium for avoiding frightened groups during file lock unlocking
CN113419870A (en) * 2021-06-20 2021-09-21 济南浪潮数据技术有限公司 Volume reading and writing method and device
CN115202884B (en) * 2022-07-26 2023-08-22 江苏安超云软件有限公司 Method for adding read write lock of high-performance system based on polling and application
CN116028437B (en) * 2023-03-29 2023-07-14 苏州浪潮智能科技有限公司 File reading method and device, RAID card, storage system and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106790694A (en) * 2017-02-21 2017-05-31 广州爱九游信息技术有限公司 The dispatching method of destination object in distributed system and distributed system
CN107632794A (en) * 2017-10-20 2018-01-26 北京小米移动软件有限公司 Read-Write Locks control method and device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
FR2762418B1 (en) * 1997-04-17 1999-06-11 Alsthom Cge Alcatel METHOD FOR MANAGING A SHARED MEMORY
US8973004B2 (en) * 2009-06-26 2015-03-03 Oracle America, Inc. Transactional locking with read-write locks in transactional memory systems
CN102999378B (en) * 2012-12-03 2015-08-26 中国科学院软件研究所 A kind of read-write lock implement method
CN104102549B (en) * 2013-04-01 2017-12-15 华为技术有限公司 A kind of method, apparatus and chip for realizing multithreading mutually exclusive operation
CN104461705B (en) * 2014-11-17 2019-02-19 华为技术有限公司 A kind of method and storage control, cluster storage system of business access

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106790694A (en) * 2017-02-21 2017-05-31 广州爱九游信息技术有限公司 The dispatching method of destination object in distributed system and distributed system
CN107632794A (en) * 2017-10-20 2018-01-26 北京小米移动软件有限公司 Read-Write Locks control method and device

Also Published As

Publication number Publication date
CN108572876A (en) 2018-09-25

Similar Documents

Publication Publication Date Title
CN108572876B (en) Method and device for realizing read-write lock
US8224977B2 (en) Using local locks for global synchronization in multi-node systems
CN110188110B (en) Method and device for constructing distributed lock
US20130138886A1 (en) Scheduler, multi-core processor system, and scheduling method
EP2945072A1 (en) Method and apparatus for processing redo data of database
US8190857B2 (en) Deleting a shared resource node after reserving its identifier in delete pending queue until deletion condition is met to allow continued access for currently accessing processor
CN110704112B (en) Method and apparatus for concurrently executing transactions in a blockchain
CN113835901A (en) Read lock operation method, write lock operation method and system
CN112099962B (en) Distributed lock implementation method and device and electronic equipment
CN104063355A (en) Method for configuring server cluster and central configuration server
CN112148480A (en) Task processing method, device and equipment based on multithreading and storage medium
KR102450133B1 (en) Distributed sysetm for managing distributed lock and operating method thereof
WO2015085914A1 (en) Database access method and device
US20210303403A1 (en) Transaction processing method, apparatus, and electronic device for blockchain
CN110908968B (en) Method, device, equipment and storage medium for avoiding frightened groups during file lock unlocking
CN112068948B (en) Data hashing method, readable storage medium and electronic device
US20090292885A1 (en) Method and apparatus for providing atomic access to memory
US20190079807A1 (en) Scalable spinlocks for non-uniform memory access
CN113961364A (en) Large-scale lock system implementation method and device, storage medium and server
CN111261206B (en) Read-write method and device, electronic equipment and readable storage medium
CN112541041A (en) Data processing method, device, server and storage medium
CN115951844B (en) File lock management method, equipment and medium of distributed file system
CN114840356B (en) Data processing method, data processing system and related device
CN113806388A (en) Service processing method and device based on distributed lock
CN109976675B (en) Data updating and reading method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder

Address after: 100089 Beijing city Haidian District Road No. 4 North wa Yitai three storey building

Patentee after: NSFOCUS Technologies Group Co.,Ltd.

Patentee after: NSFOCUS TECHNOLOGIES Inc.

Address before: 100089 Beijing city Haidian District Road No. 4 North wa Yitai three storey building

Patentee before: NSFOCUS INFORMATION TECHNOLOGY Co.,Ltd.

Patentee before: NSFOCUS TECHNOLOGIES Inc.

CP01 Change in the name or title of a patent holder
TR01 Transfer of patent right

Effective date of registration: 20220330

Address after: 100089 Beijing city Haidian District Road No. 4 North wa Yitai 5 storey building

Patentee after: NSFOCUS Technologies Group Co.,Ltd.

Patentee after: NSFOCUS TECHNOLOGIES Inc.

Patentee after: Shenzhou Lvmeng Chengdu Technology Co.,Ltd.

Address before: 100089 Beijing city Haidian District Road No. 4 North wa Yitai three storey building

Patentee before: NSFOCUS Technologies Group Co.,Ltd.

Patentee before: NSFOCUS TECHNOLOGIES Inc.

TR01 Transfer of patent right