Multi-thread concurrent access method and device

By introducing mutual trust lock mechanism and segmented lock, the problem of low efficiency of multi-threaded concurrent access to shared resources is solved, and the security and efficiency of multi-threaded concurrent write operations are improved, which is suitable for database transaction management and database page management.

CN119201485APending Publication Date: 2024-12-27HUAWEI TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310757395.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-25
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

When multi-threaded concurrent access to shared resources, the existing read and write lock mechanism leads to low thread concurrent access efficiency, especially in large-scale concurrency, the entire shared resource needs to be locked to ensure consistency, resulting in thread serial processing, affecting efficiency .

Method used

Introducing a mutual trust lock mechanism, allowing multiple threads to write operations on different data units of shared resources concurrently. The lock state is recorded through lock state variables and lock count bits, and non-exclusive write operations are realized, avoiding conflict waiting in the write lock state, and in Use segment locks when necessary to ensure exclusive access to the data unit.

Benefits of technology

It improves the efficiency and security of concurrent access to shared resources by multi-threads, reduces the competition for locks, and improves the concurrency performance of the system, especially in database transaction management and database page management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201485A_ABST
    Figure CN119201485A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a multi-thread concurrent access method, which is used for improving the efficiency of multi-thread concurrent access to shared resources. The method comprises the steps that the computing device receives a first locking request, the first locking request is used for requesting a mutual trust lock for a first thread to perform write operation on the shared resources, and the mutual trust lock is used for performing non-exclusive write operation on the shared resources; and the computing device issues a mutual trust lock to the first thread according to the first locking request. The first thread and the second thread concurrently perform write operation on the shared resources based on the mutual trust lock, and the second thread is the thread which has acquired the mutual trust lock.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the computer field, and in particular to a multi-threaded concurrent access method and device. Background Art

[0002] The read-write lock mechanism is a commonly used synchronization mechanism in multi-threaded programming. It uses certain algorithms and data structures to achieve a balance between the security and efficiency of read and write operations on shared resources. When multiple threads access the same shared resource, read-write locks are used to control the access of threads to the shared resource to prevent thread conflicts.

[0003] Currently, there are two states of locks: write lock state and read lock state. The write lock state is an exclusive lock. After adding the write lock, only one thread can read and write the shared resource. When it is already in the write lock state, other threads cannot hold the write lock state again, nor can they hold the read lock state. The read lock state is a shared lock. Multiple threads can hold the read lock at the same time and can read the data.

[0004] Currently, multi-threaded access to shared resources uses the read-write lock capability. In large-scale concurrency situations, shared resources are processed serially by multiple threads. When the scope of the protected shared resources is large, different threads have different access scopes. For example, when locking a large structure or a large array, in order to ensure the consistency of protected resources, no matter whether the thread accesses one field or an array unit, or modifies multiple fields or multiple array units, the entire shared resource is locked by adding a write lock, resulting in low efficiency of concurrent thread access to shared resources. Summary of the invention

[0005] The embodiments of the present application provide a thread concurrent access method and device for improving the efficiency of multi-thread concurrent access to shared resources.

[0006] The first aspect of the embodiment of the present application provides a multi-threaded concurrent access method, which can be executed by a computing device, or by a component of the computing device, such as a processor, chip or chip system of the computing device, or by a logic module or software that can realize all or part of the computing device functions. Taking the execution of the computing device as an example, the method of the first aspect includes: the computing device receives a first locking request, the first locking request is used to request a mutual trust lock for a first thread to perform a write operation on a shared resource, and the mutual trust lock is used to perform a non-exclusive write operation on the shared resource. Among them, the computing device is used to execute a first thread and a second thread, the first thread is used to perform a write operation on a first data unit of the shared resource, and the second thread is used to perform a write operation on a second data unit of the shared resource, and the first data unit and the second data unit are different data units. The computing device issues a mutual trust lock to the first thread according to the first locking request. After the first thread obtains the mutual trust lock, the first thread and the second thread concurrently write to the shared resource based on the mutual trust lock, and the second thread is the thread that has obtained the mutual trust lock.

[0007] The embodiment of the present application provides a mutual trust lock state, so that multiple threads in a computing device can concurrently perform write operations on different data units of a shared resource through a mutual trust lock, thereby eliminating conflict waiting in a write lock state and improving the efficiency of multi-threaded access to shared resources of the computing device.

[0008] In a possible implementation, the computing device is further used to execute a third thread, the third thread is used to perform a write operation on a shared resource global data unit, and the computing device receives a second lock request, the second lock request is used to request a mutual trust lock for the third thread to perform a concurrent write operation on the shared resource. When the first thread or the second thread acquires the mutual trust lock, the third thread waits for the mutual trust lock to be released.

[0009] In the embodiment of the present application, the computing device can issue mutual trust locks to threads that access different data units of shared resources. Threads that have conflicting data units accessing shared resources cannot obtain the mutual trust lock, thereby improving the efficiency of mutual trust threads' write operations on shared resources while ensuring the security of write operations on shared resources.

[0010] In a possible implementation, during the process of issuing a mutual trust lock to the first thread according to the first lock request, when the mutual trust lock state bit of the lock state variable is not set, the computing device sets the mutual trust lock state bit of the lock state variable according to the first lock request, and increments the lock count bit of the lock state variable. When the mutual trust lock state bit of the lock state variable is set, the computing device increments the lock count bit of the lock state variable according to the first lock request.

[0011] In an embodiment of the present application, the computing device records the mutual trust lock state corresponding to the shared resource by adding a mutual trust lock state bit in the lock state variable, and records the number of threads holding the mutual trust lock through the mutual trust lock state bit and the lock count bit. The computing device can also increase the lock count bit according to the lock request, thereby improving the feasibility of multi-threaded concurrent access to shared resources.

[0012] In one possible implementation, a computing device receives a first unlock request from a first thread, the first unlock request being used to request the release of a mutual trust lock of a shared resource. When a lock count bit of a lock state variable is greater than 1, the lock count bit of the lock state variable is decremented according to the first mutual trust lock unlock request. When the lock count bit of the lock state variable is equal to 1, the lock count bit of the lock state variable is decremented according to the first mutual trust lock unlock request, and the mutual trust lock state bit of the lock state variable is restored to being unset.

[0013] In the embodiment of the present application, the computing device can decrement the lock count bit according to the unlock request. When the lock count bit is decremented to 0, the computing device restores the mutual trust lock status bit to the set position, thereby improving the feasibility of multi-threaded concurrent access to shared resources.

[0014] In one possible implementation, the computing device is also used to execute a fourth thread, where the fourth thread is a thread that already holds a mutual trust lock, and the fourth thread is used to perform a write operation on a first data unit of a shared resource. The computing device receives a third locking request, and the third locking request is used to request a segmented lock for the fourth thread to perform a write operation on the first data unit of the shared resource, and the segmented lock is used to exclusively access the first data unit.

[0015] In an embodiment of the present application, a computing device can issue a segmented lock to a thread holding a mutual trust lock, so that while multiple threads are concurrently performing write operations on a shared resource, the thread can perform an exclusive write operation on a certain data unit of the shared resource, thereby improving the efficiency of multiple threads performing write operations on shared resources and the security of multiple threads performing write operations on shared resources.

[0016] In a possible implementation, when the first thread holds the mutual trust lock, other threads cannot hold the write lock and read lock corresponding to the shared resource. The write lock is used to perform exclusive write operations on the shared resource, and the read lock is used to perform non-exclusive read operations on the shared resource. When the first thread holds the write lock, other threads cannot hold the mutual trust lock and read lock corresponding to the shared resource. When the first thread holds the read lock, other threads cannot hold the mutual trust lock and write lock corresponding to the shared resource.

[0017] In the embodiment of the present application, different lock states corresponding to shared resources cannot appear at the same time, thereby improving the protection capabilities of different lock states.

[0018] In a possible implementation, when the mutual trust lock status bit is not set, the lock count bit is used to indicate the number of threads holding the read lock.

[0019] In the embodiment of the present application, the computing device adds a mutual trust lock status bit and uses the lock count bit to record the number of threads holding the write lock, thereby reusing the lock count bit of the read lock and improving the recording efficiency of the lock count bit.

[0020] In one possible implementation, the mutual trust lock is applied to database transaction management, and multiple different threads of the computing device concurrently write to the transaction status in the database based on the mutual trust lock. The transaction status includes active status, committed status, and rollback status. The transaction in the interactive status has not been completed, and the database operation can continue. The modification operation of the transaction in the committed status has been successfully submitted to the database, and all changes have become permanently saved. In the rollback status, the transaction has been rolled back, canceled or failed, all operations and changes have been undone, and the modified data has been restored to the state before the transaction started.

[0021] In the embodiment of the present application, the computing device can concurrently write the transaction status in the database through the mutual trust lock, thereby improving the concurrent writing performance of the transaction status.

[0022] In one possible implementation, the mutual trust lock is applied to database page management, which refers to dividing the data file of the database into a set of fixed-size data blocks, i.e., pages, and the computing device manages the use and status of these pages, including the reading and writing of the pages. Multiple different threads of the computing device concurrently write to the table entries in the database page based on the mutual trust lock.

[0023] In the embodiment of the present application, the computing device can concurrently perform write operations on pages in the database through mutual trust locks, lock a single page of the database page, and modify the locks of different areas of the database page, thereby improving the concurrent write performance of transactions in the database page.

[0024] The second aspect of the embodiment of the present application provides a multi-threaded concurrent access device, the device is used to execute a first thread and a second thread, the first thread is used to perform a write operation on a first data unit of a shared resource, the second thread is used to perform a write operation on a second data unit of a shared resource, the first data unit and the second data unit are different data units, the device includes a transceiver unit and a processing unit, wherein the transceiver unit is used to receive a first locking request, the first locking request is used to request a mutual trust lock for the first thread to perform a write operation on the shared resource, and the mutual trust lock is used to perform a non-exclusive write operation on the shared resource. The processing unit is used to issue a mutual trust lock to the first thread according to the first locking request, the first thread and the second thread of the processing unit concurrently write to the shared resource based on the mutual trust lock, and the second thread is a thread that has acquired the mutual trust lock.

[0025] In a possible implementation, the device is further used to execute a third thread, the third thread is used to perform a write operation on the shared resource global data unit, and the transceiver unit is further used to receive a second lock request, the second lock request is used to request the third thread to perform a mutual trust lock for a concurrent write operation on the shared resource. When the first thread or the second thread acquires the mutual trust lock, the third thread of the processing unit waits for the mutual trust lock to be released.

[0026] In a possible implementation, the processing unit is specifically used to set the mutual trust lock state bit of the lock state variable according to the first lock request when the mutual trust lock state bit of the lock state variable is not set, and increase the lock count bit of the lock state variable. When the mutual trust lock state bit of the lock state variable is set, the lock count bit of the lock state variable is increased according to the first lock request.

[0027] In a possible implementation, the transceiver unit is further used to receive a first unlock request from the first thread, and the first unlock request is used to request to release the mutual trust lock of the shared resource. When the lock count bit of the lock state variable is greater than 1, the processing unit is specifically used to decrement the lock count bit of the lock state variable according to the first unlock request of the mutual trust lock. When the lock count bit of the lock state variable is equal to 1, the processing unit is specifically used to decrement the lock count bit of the lock state variable according to the first unlock request of the mutual trust lock, and restore the mutual trust lock state bit of the lock state variable to unset.

[0028] In one possible implementation, the device is also used to execute a fourth thread, which is a thread that already holds a mutual trust lock. The fourth thread is used to perform a write operation on a first data unit of a shared resource. The transceiver unit is also used to receive a third locking request, and the third locking request is used to request a segmented lock for the fourth thread to perform a write operation on the first data unit of the shared resource. The segmented lock is used to exclusively access the first data unit.

[0029] In one possible implementation, the processing unit is also used to prevent other threads from holding the write lock and read lock corresponding to the shared resource when the first thread holds the mutual trust lock, the write lock is used to perform exclusive write operations on the shared resource, and the read lock is used to perform non-exclusive read operations on the shared resource.

[0030] In a possible implementation, the mutual trust lock is applied to database transaction management, and multiple different threads concurrently write to the transaction status in the database based on the mutual trust lock.

[0031] In a possible implementation, the mutual trust lock is applied to database page management, and multiple different threads concurrently perform write operations on table entries in the database page based on the mutual trust lock.

[0032] A third aspect of an embodiment of the present application provides a computing device, including a processor, the processor is coupled to a memory, the processor is used to store instructions, when the instructions are executed by the processor, the computing device executes the method described in the first aspect or any possible implementation of the first aspect.

[0033] A fourth aspect of an embodiment of the present application provides a computing device cluster, including one or more computing devices, the computing device including a processor, the processor is coupled to a memory, the processor is used to store instructions, and when the instructions are executed by the processor, the computing device cluster executes the method described in the first aspect or any possible implementation method of the first aspect.

[0034] A fifth aspect of an embodiment of the present application provides a computer-readable storage medium having instructions stored thereon. When the instructions are executed, the computer executes the method described in the first aspect or any possible implementation of the first aspect.

[0035] A sixth aspect of the embodiments of the present application provides a computer program product, which includes instructions, and is characterized in that when the instructions are executed, the computer implements the method described in the first aspect or any possible implementation method of the first aspect.

[0036] It can be understood that the beneficial effects that can be achieved by any of the multi-threaded concurrent access devices, computing devices, computer-readable media or computer program products provided above can refer to the beneficial effects in the corresponding computing system and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 A schematic diagram of a concurrent thread access system architecture provided in an embodiment of the present application;

[0038] Figure 2 A flowchart of a thread concurrent access method provided in an embodiment of the present application;

[0039] Figure 3 A schematic diagram of different lock states provided in an embodiment of the present application;

[0040] Figure 4 A schematic diagram of another different lock state provided in an embodiment of the present application;

[0041] Figure 5 A schematic diagram of a lock state variable provided in an embodiment of the present application;

[0042] Figure 6a A schematic diagram of a process for applying for a mutual trust lock provided in an embodiment of the present application;

[0043] Figure 6bA schematic diagram of a process for releasing a mutual trust lock provided in an embodiment of the present application;

[0044] Figure 7 A schematic diagram of accessing a shared resource based on a segmented lock provided in an embodiment of the present application;

[0045] Figure 8a A schematic diagram for comparing system concurrency provided in an embodiment of the present application;

[0046] Figure 8b Another schematic diagram for comparing system concurrency provided in an embodiment of the present application;

[0047] Fig. 9 A schematic diagram of a thread concurrency device provided in an embodiment of the present application;

[0048] Fig.10 A schematic diagram of the structure of a computing device provided in an embodiment of the present application;

[0049] Fig.11 A schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;

[0050] Fig.12 A schematic diagram of the structure of another computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The embodiments of the present application provide a multi-threaded concurrent access method and device for improving the efficiency of multi-threaded concurrent access.

[0052] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0053] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0054] First, some terms involved in the embodiments of the present application are introduced to facilitate technical personnel in this field to understand the solution.

[0055] Read-write lock is a concurrency control mechanism used to optimize the contention of read and write operations. Read-write lock contains two mutually exclusive locks: read lock and write lock. As long as no write lock is acquired, multiple read locks can be acquired at the same time, and when a write lock is acquired, all threads of read operations and threads of write operations will be blocked until the write lock is released. When a thread acquires the write lock, other threads cannot acquire the read lock or write lock. When a thread acquires the read lock, other threads can only acquire the read lock but not the write lock.

[0056] An atomic operation is an operation that can be completed in a single, indivisible step. In computer science, an atomic operation usually refers to an operation in a multithreaded environment that is either fully executed successfully or fully failed and cannot be completed partially. Atomic operations can ensure data synchronization and consistency in a multithreaded environment in a computer multiprocessing system. Operations include reading, writing, comparing, and exchanging. When using atomic operations, each operation is atomic.

[0057] Segmented locking is a way of using locks. The computing device divides shared resources into multiple segments. Each segment has an independent lock to control concurrent access, narrow the scope of concurrent access, reduce lock contention, and improve concurrent performance.

[0058] The following describes the multi-threaded concurrent access method and device provided by the embodiments of the present application in conjunction with the accompanying drawings.

[0059] See also Figure 1 , Figure 1 A schematic diagram of a system architecture for concurrent access of threads provided in an embodiment of the present application. Figure 1 In the example shown, the computing device system 100 includes a processor 101 and a memory 102. The processor 101 runs multiple threads, the memory 102 stores shared resources, and the multiple threads in the processor 101 can access the shared resources in the memory 102. The specific functions of each part of the computing device system 100 are described below.

[0060] The processor 101 user performs computing tasks of the computing device. When the processor 101 performs computing tasks, the processor 101 can decompose the computing tasks into multiple threads for execution. The processor 101 can control the time slices of different threads to ensure that each thread can be executed. For example, Figure 1 In the example shown, the processor 101 is capable of scheduling thread 1, thread 2, and thread n to access different data units of a shared resource.

[0061] The processor 101 is also used to control the access mechanism of multiple threads to access shared data. The processor 101 can control the lock state corresponding to the shared resource, and the lock state corresponding to the shared resource includes a write lock state, a read lock state, and a mutual trust lock state. The write lock state only allows one thread to write to the shared resource, and the read lock state allows multiple threads to read the shared resource. The mutual trust lock state is used for multiple mutually trusted threads to concurrently write to the shared resource. Mutually trusted threads refer to threads that will not access the same data unit of the shared resource at the same time.

[0062] The memory 102 is used to store the shared resources of the computing device, and the shared resources include the data generated by the processor 101 during the execution of the computing task. The processor 101 can access the shared resources stored in the memory 102, for example, Figure 1 In the example shown, processor 101 can read data of the first data unit from the shared resources in memory 102 by executing thread 1, or processor 101 can write data in the second data unit of the shared resources in memory 102 by executing thread 2, or processor 101 can access all data units of the shared resources in memory 102 by executing thread 5.

[0063] See also Figure 2 , Figure 2 A schematic diagram of a multi-threaded concurrent access process provided by an embodiment of the present application. Figure 2 In the example shown, the multi-threaded concurrent access provided by the embodiment of the present application includes the following steps:

[0064] 201. A computing device receives a first locking request, where the first locking request is used to request a mutual trust lock for a first thread to perform a write operation on a shared resource, where the mutual trust lock is used to perform a non-exclusive write operation on the shared resource.

[0065] When a computing device is executing a computing task, it accesses shared memory resources by executing multiple threads. To avoid access conflicts of shared resources, only threads holding locks can access shared resources. For example, a thread holding a write lock can perform exclusive write operations on shared resources, and multiple threads holding read locks can concurrently read shared resources.

[0066] The embodiment of the present application also provides a lock state, namely a mutual trust lock, where multiple threads holding the mutual trust lock in the computing device can concurrently write to the shared resource. The mutual trust lock state provided by the embodiment of the present application is introduced below in conjunction with the first thread and the second thread.

[0067] The computing device receives a first lock request, and the first lock request is used to request a mutual trust lock for the first thread to perform a write operation on a shared resource. The mutual trust lock is used to perform a non-exclusive write operation on the shared resource, that is, multiple threads holding the mutual trust lock can concurrently write to the shared resource. The computing device can issue mutual trust locks to multiple mutually trusted threads, and multiple mutually trusted threads refer to threads that will not access the same data unit of the shared resource at the same time. For example, the first thread performs a write operation on the first data unit of the shared resource, and the second thread performs a write operation on the second data unit of the shared resource. The first data unit and the second data unit are different data units, and the first thread and the second thread are mutually trusted threads.

[0068] See also Figure 3 , Figure 3 A schematic diagram of different lock states provided in an embodiment of the present application. Figure 3 In the example shown, the lock state includes a write lock state, a read lock state and a mutual trust lock state, wherein in the write lock state, the locked part of the threads can exclusively read and write the shared resources, the read lock state, the locked part of the multiple threads can concurrently read the shared resources, and in the mutual trust lock state, the locked part of the multiple threads can concurrently read and write the shared resources.

[0069] For example, in Figure 3 In the example shown, after thread 1 acquires the write lock, when thread 1 writes to the global data of the shared resource, thread 2 and thread 3 cannot write to the global array of the shared resource and wait for thread 1 to write. Thread 1 exclusively writes to the global data of the shared resource. After thread 1 releases the write lock, thread 2 acquires the write lock and exclusively writes to the global data of the shared resource.

[0070] For example, in Figure 3 In the example shown, thread 1, thread 2, and thread 3 can simultaneously acquire the read lock, and thread 1 concurrently performs a read operation on the global data of the shared resource, wherein thread 1 performs a read operation on data unit 1 of the global array, thread 2 performs a read operation on data unit 3 of the global array, and thread 3 performs a read operation on data unit 5 of the global array.

[0071] exist Figure 3 In the example shown, when thread 1, thread 2, and thread n respectively access different data units of global data, thread 1, thread 2, and thread 3 can request a mutual trust lock from the computing device. After thread 1, thread 2, and thread n obtain the mutual trust lock, thread 1, thread 2, and thread 3 can concurrently access the global array of shared resources. For example, thread 1 writes to data unit 1 of the global array, while thread 2 writes to data unit 2 of the global array, and while thread 3 writes to data unit 5 of the global array.

[0072] In a possible implementation, when the first thread holds the mutual trust lock, other threads cannot hold the write lock and read lock corresponding to the shared resource. The write lock is used to perform exclusive write operations on the shared resource, and the read lock is used to perform non-exclusive read operations on the shared resource.

[0073] In the embodiments of the present application, different lock states cannot appear at the same time. The write lock can only be held by one thread at a time. When the lock state is in the write lock state, other threads cannot hold the read lock and the mutual trust lock. The read lock can be held by multiple threads at the same time. When the lock state is in the read lock state, other threads cannot hold the write lock and the mutual trust lock. The mutual trust lock can be held by multiple threads at the same time. When the lock state is in the mutual trust lock state, other threads cannot hold the write lock and the read lock.

[0074] See also Figure 4 , Figure 4 A schematic diagram of the relationship between different lock states provided in an embodiment of the present application. Figure 4 In the example shown, when a thread holds a write lock, other threads cannot hold the write lock, read lock, and mutual trust lock; when a thread holds a read lock, other threads cannot hold the write lock and mutual trust lock; when a thread holds the mutual trust lock, other threads cannot hold the write lock and read lock.

[0075] For example, in Figure 4 In the example shown, when thread 1 is in the write lock state, threads 2 to 7 cannot obtain the write lock, read lock, and mutual trust lock, and threads 2 to 7 wait for thread 1 to release the write lock. After thread 1 releases the write lock, thread 2 obtains the write lock, and threads 1, 3 to 7 cannot obtain the write lock, read lock, and mutual trust lock. After thread 2 releases the write lock, threads 3 and 4 obtain the read lock, and threads 3 and 4 can perform concurrent read operations on shared resources. At this time, threads 1, 2, and 5 to 7 cannot obtain the write lock and mutual trust lock.

[0076] exist Figure 4 In the example shown, when thread 5 is in the mutual trust lock state, threads 1 to 6 and threads 5 to 7 cannot obtain the write lock and read lock, and threads 6 to 7 can obtain the mutual trust lock. Since threads 5 to 7 are mutually trusted threads, after threads 5 to 7 obtain the mutual trust lock, they can concurrently perform write operations on different data units of the shared resource.

[0077] In one possible implementation, the computing device receives a second lock request, the second lock request is used to request a third thread to perform a mutual trust lock for concurrent write operations on a shared resource, and the third thread is used to perform a write operation on a global data unit of the shared resource. Since there is a conflict in the data units of the first thread and the third thread for writing operations on the shared resource, the first thread and the third thread are not mutually trusted threads. When the first thread or the second thread obtains the mutual trust lock, the third thread cannot obtain the mutual trust lock and waits for the mutual trust lock to be released.

[0078] Please continue reading Figure 3 ,exist Figure 3 In the example shown, since threads 1, 2, and 3 access different data units of global data, threads 1, 2, and 3 can simultaneously hold the mutual trust lock corresponding to the shared resource. When thread m needs to access the global array, thread m is a non-mutually trusting thread with thread 1, 2, and n, respectively, and therefore, thread m cannot obtain the mutual trust lock.

[0079] In one possible implementation, the computing device receives a write lock application request, and the computing device reads the lock state variable to determine whether it is in a read lock state, a write lock state, or a mutual trust lock state. If it is already locked, then the write lock application fails and a new application is made. During this period, it can be retried immediately or it can wait to be awakened by other release processes. If it is not locked, then the variable write lock state bit needs to be set, and the variable needs to be atomically operated. If the modification is successful, the write lock is successfully added. If the modification fails, it means that other tasks have first locked and modified the variable value during this period, then the lock fails, and the process of retrying, waiting, or other processes is entered.

[0080] In one possible implementation, the computing device receives a read lock application request, and the computing device first reads the lock state variable to determine whether it is already in a write lock state or a mutual trust lock state. If it has been written or mutually locked, then the read lock application fails and a new application is made. During this period, it can be retried immediately or wait to be awakened by other release processes. If it has not been written or mutually locked, then the variable read lock count bit needs to be increased by 1, and the lock state variable needs to be atomically operated. If the modification is successful, the read lock is successfully added. If the modification fails, it means that other tasks have modified the variable value during this period, and the lock fails, and a retry or other process is entered.

[0081] 202. The computing device issues a mutual trust lock to the first thread according to the first locking request.

[0082] The computing device issues a mutual trust lock to the first thread according to the first locking request. Specifically, the computing device modifies the lock state variable corresponding to the shared resource according to the first locking request. The lock state variable in the embodiment of the present application includes a write lock state bit, a mutual trust lock state bit, and a lock count bit, wherein the write lock state bit is used to indicate whether the lock is in a write lock state, the mutual trust lock state is used to indicate whether the lock is in a mutual trust lock state, and the lock count bit is used to indicate the number of threads holding a read lock or the number of threads holding a mutual trust lock. Specifically, when the mutual trust lock state bit is not set, the lock count bit is used to indicate the number of threads holding a read lock, and when the mutual trust lock state bit is set, the lock count bit is used to indicate the number of threads holding a mutual trust lock.

[0083] See also Figure 5 , Figure 5A schematic diagram of a lock state variable provided for the implementation of this application. Figure 5 In the example shown, the first bit of the lock state variable is the write lock state bit. When the write lock state bit is not set, there is no thread in the write lock state. When the write lock state bit is set, there is a thread in the write lock state, and the thread holding the write lock can read the read lock. The second bit of the lock state variable is the mutual trust lock state bit. When the mutual trust lock state bit is not set, the lock count bit is the count of threads holding the read lock. When the mutual trust lock state bit is set, there is at least one thread in the mutual trust lock state, and the lock count bit is the count of threads holding the mutual trust lock.

[0084] exist Figure 5 In the example shown, the write lock status bit of the lock status variable is 0, the mutual trust lock status bit is 1, and the lock count bit is 11 (binary). The computing device has three threads in the mutual trust lock state, and the three threads in the mutual trust lock state can concurrently perform write operations on different data units of the shared resource.

[0085] In a possible implementation, when the mutual trust lock state bit of the lock state variable is not set, the computing device sets the mutual trust lock state bit of the lock state variable according to the first lock request, and increments the lock count bit of the lock state variable. When the mutual trust lock state bit of the lock state variable is set, the computing device increments the lock count bit of the lock state variable according to the first lock request.

[0086] See also Figure 6a , Figure 6a A schematic diagram of a process for applying for a mutual trust lock provided in an embodiment of the present application. Figure 6a In the example shown, after the thread of the computing device requests to apply for a mutual trust lock, the computing device queries the current lock state. When the lock state is a read lock state or a write lock state, the thread of the computing device waits to obtain the mutual trust lock. When the lock state is an unlocked lock or a mutual trust lock state, the thread of the computing device can obtain the mutual trust lock. After the thread of the computing device obtains the mutual trust lock, the computing device sets the mutual trust lock state bit of the lock state variable and increments the lock count bit.

[0087] Please continue reading Figure 5 ,exist Figure 5 In the example shown, the write lock state of the lock state variable is 0, the mutual trust lock state bit is 1, and the lock count bit is 11 (binary). When a thread applies for a mutual trust lock, there are 3 threads holding the mutual trust lock. The computing device adds 1 to the lock count bit of the lock state variable according to the lock request. The modified lock count bit is 100 (binary), that is, the number of threads holding the mutual trust lock is 4.

[0088] In one possible implementation, a computing device receives a first unlock request from a first thread, the first unlock request being used to request the release of a mutual trust lock of a shared resource. When a lock count bit of a lock state variable is greater than 1, the lock count bit of the lock state variable is decremented according to the first mutual trust lock unlock request. When the lock count bit of the lock state variable is equal to 1, the lock count bit of the lock state variable is decremented according to the first mutual trust lock unlock request, and the mutual trust lock state bit of the lock state variable is restored to being unset.

[0089] See also Figure 6b , Figure 6b A schematic diagram of a process for releasing a mutual trust lock provided in an embodiment of the present application. Figure 6b In the example shown, after the thread of the computing device requests to release the mutual trust lock, the computing device queries the current lock state and decrements the lock count bit of the lock state variable. When the lock count bit of the lock state variable is 1, the computing device decrements the lock count bit of the lock state variable and restores the mutual trust lock state bit to the set position. After the interlock lock state is restored to the set position, the mutual trust lock is released.

[0090] Please continue reading Figure 5 ,exist Figure 5 In the example shown, the write lock state of the lock state variable is 0, the mutual trust lock state bit is 1, and the lock count bit is 11 (binary). When a thread applies to release the mutual trust lock, there are 3 threads holding the mutual trust lock. The computing device subtracts 1 from the lock count bit of the lock state variable according to the unlocking request. The modified lock count bit is 10 (binary), that is, the number of threads holding the mutual trust lock is 4.

[0091] In a possible implementation, the computing device is further used to execute a fourth thread, the fourth thread is a thread that has held a mutual trust lock, and the fourth thread is used to perform a write operation on a first data unit of a shared resource. The computing device receives a third lock request, the third lock request is used to request a segment lock for the fourth thread to perform a write operation on the first data unit of the shared resource, and the segment lock is used to exclusively access the first data unit. When the fourth thread holds the segment lock, the fourth thread can exclusively access the first data unit of the shared resource.

[0092] In the embodiment of the present application, when the threads holding the mutual trust lock need to access the same data unit of the shared resource, the computing device can control the threads holding the mutual trust lock to serially access the same data unit of the shared resource through the segmentation lock. For example, if the first thread holding the mutual trust lock and the fourth thread holding the mutual trust lock both need to access the first data unit of the shared resource, the computing device can control the first thread and the second hyperthread to serially access the first data unit through the segmentation lock.

[0093] See also Figure 7 , Figure 7A schematic diagram of accessing a shared resource based on a segment lock is provided in an embodiment of the present application. Figure 7 In the example shown, thread 1 and thread 2 are threads holding mutual trust locks. Thread 1 and thread 2 can concurrently access different data units in the global array. When data unit 3 is concurrently accessed by thread 1 and thread 2, the computing device controls thread 1 and thread 2 to serially access data unit 3 through the segment lock. When thread 1 holds the segment lock corresponding to data unit 3, thread 1 can write to data unit 3. After thread 1 releases the segment lock corresponding to data unit 3, thread 2 can obtain the segment lock corresponding to data unit 3 and perform an exclusive write operation on data unit 3.

[0094] Similarly, in Figure 7 In the example shown, thread m and thread n are also threads holding mutual trust locks. The computing device controls thread m and thread n to serially access data unit 7 through segment locks. When thread m holds the segment lock corresponding to data unit 7, thread m can write to data unit 7. After thread n releases the segment lock corresponding to data unit 7, thread n can obtain the segment lock corresponding to data unit 7 and perform exclusive write operations on data unit 7.

[0095] exist Figure 7 In the example shown, the computing device can issue segment locks to thread n and thread m that hold mutual trust locks, so that while thread n and thread m concurrently write to shared resources, thread n and thread m can perform exclusive write operations on data unit 7 segments of the shared resource, thereby improving the security of multi-threaded write operations on shared resources.

[0096] In the implementation of this application, the computing device can add a more fine-grained sub-lock, namely a segment lock, on the basis of the mutual trust lock. The computing device can modify different data units in the shared resource through the mutual trust lock, and the segment lock protects the same data unit in the shared resource to be modified only serially, thereby improving the security of multi-threaded write operations on the same data unit of the shared resource.

[0097] 203. The first thread and the second thread concurrently perform a write operation on the shared resource based on the mutual trust lock, and the second thread is the thread that already holds the mutual trust lock.

[0098] After the first thread acquires the mutual trust lock, the first thread and the second thread concurrently write to the shared resource, and the second thread is the thread that has acquired the mutual trust lock. It should be noted that the number of the first thread and the second thread in the embodiment of the present application is not limited.

[0099] In one possible implementation, the mutual trust lock is applied to database transaction management, and multiple different threads of the computing device concurrently write to the transaction status in the database based on the mutual trust lock. The transaction status includes active status, committed status, and rollback status. The transaction in the interactive status has not been completed, and the database operation can continue. The modification operation of the transaction in the committed status has been successfully submitted to the database, and all changes have become permanently saved. In the rollback status, the transaction has been rolled back, canceled or failed, all operations and changes have been undone, and the modified data has been restored to the state before the transaction started.

[0100] For example, in the database openGauss, the computing device needs to update the transaction status when the transaction is committed. The transaction status is an array. The computing device manages the transaction status data globally and regularly performs snapshot scans on the transaction status array. Therefore, the computing device needs to lock the entire array so that the computing device's thread can only access or modify one of the transaction array units at a time. The computing device improves the concurrency of the transaction status write operation by changing the thread's read lock and write lock to a mutual trust lock.

[0101] See also Figure 8a , Figure 8a A schematic diagram of using mutual trust locks to improve the concurrency capability of computing devices provided in an embodiment of the present application. Figure 8a In the coordinate system shown, the horizontal axis is the number of concurrent transactions, and the vertical axis is the number of transactions per second (TPS) of the computing device. The computing device can optimize the transaction update operation of the database by using the mutual trust lock. Figure 8a It can be seen from the example shown that after the computing device optimizes the transaction update operation using the mutual trust lock, the TPS of the transaction update operation is increased from 100,000 per second to 490,000 per second, an increase of 5 times.

[0102] See also Figure 8b , Figure 8b A schematic diagram of using mutual trust locks to improve the concurrency capability of computing devices provided in an embodiment of the present application. Figure 8b In the example shown, the computing device can optimize the transaction insert operation of the database by using the mutual trust lock. Figure 8b It can be seen from the example shown that after the computing device optimizes the transaction insertion operation using the mutual trust lock, the TPS of the computing device performing the transaction insertion operation is increased from 100,000 per second to 500,000 per second, an increase of 5 times.

[0103] In one possible implementation, mutual trust locks are applied to database page management. Database page management refers to dividing the data files of the database into a set of pages of fixed size. The computing device manages the use and status of these pages, including the reading and writing of pages. Multiple different threads of the computing device concurrently write to table items in the database based on mutual trust locks.

[0104] For example, in a MySQL-based database, when a computing device needs to write multiple table items in a database page, multiple threads of the computing device can concurrently write different table items in the database page through mutual trust locks, thereby improving the computing device's management efficiency of data pages.

[0105] It should be noted that the mutual trust lock provided in the embodiment of the present application may not be limited to specific products. Software such as operating systems and databases can implement and use mutual trust locks. When application software, middleware, and underlying software need to use mutual trust locks, they can call the mutual trust lock library function interface provided in the operating system, or they can directly implement the mutual trust lock function in their own software. There is no specific limitation.

[0106] It can be seen from the above embodiments that the embodiments of the present application provide that multiple threads in a computing device concurrently write to different data units of a shared resource through a mutual trust lock, thereby improving the efficiency of multi-threaded access to shared resources of the computing device.

[0107] The above introduces the multi-threaded concurrent access method provided by the embodiment of the present application. The following introduces the multi-threaded concurrent access device provided by the embodiment of the present application.

[0108] See also Fig. 9 , Fig. 9 A schematic diagram of the structure of a multi-threaded concurrent access device provided in an embodiment of the present application. Fig. 9 In the example shown, the multi-threaded concurrent access device is used to implement the various steps executed by the computing device in the above embodiments. The multi-threaded concurrent access device 900 includes a transceiver unit 901 and a processing unit 902 .

[0109] Among them, the transceiver unit 901 is used to receive a first locking request, and the first locking request is used to request a mutual trust lock for the first thread to perform a write operation on a shared resource, and the mutual trust lock is used to perform a non-exclusive write operation on the shared resource. The processing unit 902 is used to issue a mutual trust lock to the first thread according to the first locking request, and the first thread and the second thread of the processing unit 902 concurrently write to the shared resource based on the mutual trust lock, and the second thread is a thread that has obtained the mutual trust lock. The first thread is used to write to the first data unit of the shared resource, and the second thread is used to write to the second data unit of the shared resource. The first data unit and the second data unit are different data units.

[0110] In a possible implementation, the device is further used to execute a third thread, the third thread is used to perform a write operation on the shared resource global data unit, and the transceiver unit 901 is further used to receive a second lock request, the second lock request is used to request the third thread to perform a mutual trust lock for a concurrent write operation on the shared resource. After the first thread or the second thread acquires the mutual trust lock, the third thread of the processing unit 902 waits for the mutual trust lock to be released.

[0111] In a possible implementation, the processing unit 902 is specifically configured to, when the mutual trust lock state bit of the lock state variable is not set, set the mutual trust lock state bit of the lock state variable according to the first lock request, and increment the lock count bit of the lock state variable. When the mutual trust lock state bit of the lock state variable is set, increment the lock count bit of the lock state variable according to the first lock request.

[0112] In a possible implementation, the transceiver unit 901 is further used to receive a first unlock request from the first thread, and the first unlock request is used to request to release the mutual trust lock of the shared resource. When the lock count bit of the lock state variable is greater than 1, the processing unit 902 is specifically used to decrement the lock count bit of the lock state variable according to the first unlock request of the mutual trust lock. When the lock count bit of the lock state variable is equal to 1, the processing unit 902 is specifically used to decrement the lock count bit of the lock state variable according to the first unlock request of the mutual trust lock, and restore the mutual trust lock state bit of the lock state variable to unset.

[0113] In one possible implementation, the device is also used to execute a fourth thread, which is a thread that already holds a mutual trust lock. The fourth thread is used to perform a write operation on a first data unit of a shared resource. The transceiver unit 901 is also used to receive a third locking request, and the third locking request is used to request a segmented lock for the fourth thread to perform a write operation on the first data unit of the shared resource. The segmented lock is used to exclusively access the first data unit.

[0114] In one possible implementation, the processing unit 902 is also used to prevent other threads from holding the write lock and read lock corresponding to the shared resource when the first thread holds the mutual trust lock, the write lock is used to perform exclusive write operations on the shared resource, and the read lock is used to perform non-exclusive read operations on the shared resource.

[0115] In a possible implementation, the mutual trust lock is applied to database transaction management, and multiple different threads concurrently write to the transaction status in the database based on the mutual trust lock.

[0116] In a possible implementation, the mutual trust lock is applied to database page management, and multiple different threads concurrently perform write operations on table entries in the database page based on the mutual trust lock.

[0117] It should be understood that the division of the units in the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And the units in the device can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some units can also be implemented in the form of software calling through processing elements, and some units can be implemented in the form of hardware. For example, each unit can be a separately established processing element, or it can be integrated in a certain chip of the device. In addition, it can also be stored in the memory in the form of a program, and called and executed by a certain processing element of the device. The function of the unit. In addition, all or part of these units can be integrated together, or they can be implemented independently. The processing element described here can also be a processor, which can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each unit above can be implemented by an integrated logic circuit of hardware in the processor element or in the form of software calling through a processing element.

[0118] It is worth noting that, for the above method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present invention is not limited to the described order of actions. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required for the present invention.

[0119] Other reasonable step combinations that can be thought of by those skilled in the art based on the above description also fall within the scope of protection of the present invention. Secondly, those skilled in the art should also be familiar with the fact that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the present invention.

[0120] See also Fig.10 , Fig.10 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. Fig.10 As shown, the computing device 1000 includes: a processor 1001, a memory 1002, a communication interface 1003 and a bus 1004. The processor 1001, the memory 1002 and the communication interface 1003 are coupled via a bus (not marked in the figure). The memory 1002 stores instructions. When the execution instructions in the memory 1002 are executed, the computing device 1000 executes the method executed by the computing device in the above method embodiment.

[0121] The computing device 1000 may be one or more integrated circuits configured to implement the above method, such as one or more application specific integrated circuits (ASIC), or one or more digital signal processors (DSP), or one or more field programmable gate arrays (FPGA), or a combination of at least two of these integrated circuit forms. For another example, when a unit in the device can be implemented in the form of a processing element scheduler, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call a program. For another example, these units may be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0122] The processor 1001 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. A general-purpose processor may be a microprocessor or any conventional processor.

[0123] The memory 1002 may be a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memories. Among them, the nonvolatile memory may be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable ROM (EPROM), an electrically erasable programmable ROM (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).

[0124] The memory 1002 stores executable program codes, and the processor 1001 executes the executable program codes to respectively implement the functions of the aforementioned transceiver unit and the processing unit, thereby implementing the aforementioned multi-threaded concurrent access method. That is, the memory 1002 stores instructions for executing the aforementioned multi-threaded concurrent access method.

[0125] The communication interface 1003 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 1000 and other devices or a communication network.

[0126] In addition to the data bus, the bus 1004 may also include a power bus, a control bus, a status signal bus, etc. The bus may be a peripheral component interconnect express (PCIe) bus, or an extended industry standard architecture (EISA) bus, a unified bus (Ubus or UB), a compute express link (CXL), a cache coherent interconnect for accelerators (CCIX), etc. The bus may be divided into an address bus, a data bus, a control bus, etc.

[0127] See also Fig.11 , Fig.11 A schematic diagram of a computing device cluster provided in an embodiment of the present application. Fig.11 As shown, the computing device cluster 1100 includes at least one computing device 1000 .

[0128] like Fig.11 As shown, the computing device cluster 1100 includes at least one computing device 1000. The memory 1002 in one or more computing devices 1000 in the computing device cluster 1100 may store the same instructions for executing the above multi-threaded concurrent access method.

[0129] In some possible implementations, the memory 1002 of one or more computing devices 1000 in the computing device cluster 1100 may also store some instructions for executing the multi-threaded concurrent access method. In other words, the combination of one or more computing devices 1000 can jointly execute the instructions for executing the multi-threaded concurrent access method.

[0130] It should be noted that the memory 1002 in different computing devices 1000 in the computing device cluster 1100 may store different instructions, which are respectively used to execute part of the functions of the multi-threaded concurrent access device. That is, the instructions stored in the memory 1002 in different computing devices 1000 may implement the functions of one or more modules.

[0131] In some possible implementations, one or more computing devices 1000 in the computing device cluster 1100 may be connected via a network, which may be a wide area network or a local area network.

[0132] See also Fig.12 , Fig.12A schematic diagram of computer devices in a computer cluster connected via a network provided in an embodiment of the present application. Fig.12 As shown, two computing devices 1000A and 1000B are connected via a network. Specifically, they are connected to the network via a communication interface in each computing device.

[0133] In a possible implementation, the memory in the computing device 1000A stores instructions for executing the functions of the transceiver unit, and the memory in the computing device 1000B stores instructions for executing the functions of the processing unit.

[0134] It should be understood that Fig.12 The functions of the computing device 1000A shown in FIG. 1000A may also be completed by multiple computing devices. Similarly, the functions of the computing device 1000B may also be completed by multiple computing devices.

[0135] In another embodiment of the present application, a computer-readable storage medium is provided, in which computer-executable instructions are stored. When the processor of the device executes the computer-executable instructions, the device executes the method executed by the computing device in the above method embodiment.

[0136] In another embodiment of the present application, a computer program product is provided, the computer program product includes computer execution instructions, the computer execution instructions are stored in a computer readable storage medium. When the processor of the device executes the computer execution instructions, the device executes the method executed by the computing device in the above method embodiment.

[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0138] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0139] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0140] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0141] If 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. Based on this understanding, the technical solution of the present application is 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 a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.

Claims

1. A multi-threaded concurrent access method, characterized in that: The method is applied to a computing device, the computing device is used to execute a first thread and a second thread, the first thread is used to perform a write operation on a first data unit of a shared resource, the second thread is used to perform a write operation on a second data unit of the shared resource, the first data unit and the second data unit are different data units, and the method includes: receiving a first lock request, where the first lock request is used to request a mutual trust lock for the first thread to perform a write operation on the shared resource, where the mutual trust lock is used to perform a non-exclusive write operation on the shared resource; issuing a mutual trust lock to the first thread according to the first locking request; The first thread and the second thread concurrently perform a write operation on the shared resource based on the mutual trust lock, and the second thread is a thread that has acquired the mutual trust lock.

2. The method according to claim 1, characterized in that The computing device is further configured to execute a third thread, wherein the third thread is configured to perform a write operation on the shared resource global data unit, and the method further comprises: receiving a second lock request, where the second lock request is used to request the third thread to perform a mutual trust lock for a concurrent write operation on the shared resource; After the first thread or the second thread acquires the mutual trust lock, the third thread waits for the mutual trust lock to be released.

3. The method according to claim 1 or 2, characterized in that: The issuing of a mutual trust lock to the first thread according to the first lock request includes: When the mutual trust lock state bit of the lock state variable is not set, setting the mutual trust lock state bit of the lock state variable according to the first lock request, and increasing the lock count bit of the lock state variable; When the mutual trust lock state bit of the lock state variable is set, the lock count bit of the lock state variable is incremented according to the first lock request.

4. The method according to claim 3, characterized in that The method further comprises: receiving a first unlocking request of the first thread, where the first unlocking request is used to request to release the mutual trust lock of the shared resource; When the lock count bit of the lock state variable is greater than 1, the lock count bit of the lock state variable is decremented according to the first unlocking request of the mutual trust lock; When the lock count bit of the lock state variable is equal to 1, the lock count bit of the lock state variable is decremented according to the mutual trust lock first unlocking request, and the mutual trust lock state bit of the lock state variable is restored to unset.

5. The method according to any one of claims 1 to 4, characterized in that The computing device is further configured to execute a fourth thread, the fourth thread being a thread that has held the mutual trust lock, and the fourth thread being configured to perform a write operation on the first data unit of the shared resource, and the method further comprising: A third lock request is received, where the third lock request is used to request a segment lock for the fourth thread to perform a write operation on a first data unit of the shared resource, where the segment lock is used to exclusively access the first data unit.

6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: When the first thread holds the mutual trust lock, other threads cannot hold the write lock and read lock corresponding to the shared resource, the write lock is used to perform exclusive write operations on the shared resource, and the read lock is used to perform non-exclusive read operations on the shared resource.

7. The method according to any one of claims 1 to 6, characterized in that The mutual trust lock is applied to database transaction management, and the method further includes: Multiple different threads concurrently write the transaction status in the database based on the mutual trust lock.

8. The method according to any one of claims 1 to 6, characterized in that The mutual trust lock is applied to database page management, and the method further includes: Multiple different threads concurrently perform write operations on table entries in the database page based on the mutual trust lock.

9. A multi-threaded concurrent access device, characterized in that: The device is used to execute a first thread and a second thread, the first thread is used to perform a write operation on a first data unit of a shared resource, the second thread is used to perform a write operation on a second data unit of the shared resource, the first data unit and the second data unit are different data units, and the device includes: A transceiver unit, configured to receive a first locking request, wherein the first locking request is used to request a mutual trust lock for the first thread to perform a write operation on the shared resource, and the mutual trust lock is used to perform a non-exclusive write operation on the shared resource; A processing unit, configured to issue a mutual trust lock to the first thread according to the first locking request; The first thread and the second thread of the processing unit concurrently perform a write operation on the shared resource based on the mutual trust lock, and the second thread is a thread that has acquired the mutual trust lock.

10. The device according to claim 9, characterized in that The device is further used to execute a third thread, the third thread is used to perform a write operation on the shared resource global data unit, and the transceiver unit is further used to: receiving a second lock request, where the second lock request is used to request the third thread to perform a mutual trust lock for a concurrent write operation on the shared resource; After the first thread or the second thread acquires the mutual trust lock, the third thread of the processing unit waits for the mutual trust lock to be released.

11. The device according to claim 9 or 10, characterized in that The processing unit is specifically used for: When the mutual trust lock state bit of the lock state variable is not set, setting the mutual trust lock state bit of the lock state variable according to the first lock request, and increasing the lock count bit of the lock state variable; When the mutual trust lock state bit of the lock state variable is set, the lock count bit of the lock state variable is incremented according to the first lock request.

12. The device according to claim 11, characterized in that The transceiver unit is also used for: receiving a first unlocking request of the first thread, where the first unlocking request is used to request to release the mutual trust lock of the shared resource; When the lock count bit of the lock state variable is greater than 1, the processing unit is specifically configured to decrement the lock count bit of the lock state variable according to the first unlocking request of the mutual trust lock; When the lock count bit of the lock state variable is equal to 1, the processing unit is specifically configured to decrement the lock count bit of the lock state variable according to the mutual trust lock first unlocking request, and restore the mutual trust lock state bit of the lock state variable to unset.

13. The device according to any one of claims 9 to 12, characterized in that The device is further used to execute a fourth thread, the fourth thread is a thread that has held the mutual trust lock, the fourth thread is used to perform a write operation on the first data unit of the shared resource, and the transceiver unit is further used to: A third lock request is received, where the third lock request is used to request a segment lock for the fourth thread to perform a write operation on a first data unit of the shared resource, where the segment lock is used to exclusively access the first data unit.

14. The device according to any one of claims 9 to 13, characterized in that The processing unit is also used for: When the first thread holds the mutual trust lock, other threads cannot hold the write lock and read lock corresponding to the shared resource, the write lock is used to perform exclusive write operations on the shared resource, and the read lock is used to perform non-exclusive read operations on the shared resource.

15. The device according to any one of claims 9 to 14, characterized in that The mutual trust lock is applied to database transaction management, and the processing unit is also used for multiple different threads to concurrently write transaction status in the database based on the mutual trust lock.

16. The device according to any one of claims 9 to 14, characterized in that The mutual trust lock is applied to database page management, and the processing unit is also used for multiple different threads to concurrently perform write operations on table entries in the database page based on the mutual trust lock.

17. A computing device, characterized in that The device comprises a processor coupled to a memory, wherein the processor is used to store instructions. When the instructions are executed by the processor, the computing device performs the method according to any one of claims 1 to 8.

18. A computing device cluster, characterized in that: The system comprises one or more computing devices, wherein the computing devices include a processor, the processor is coupled to a memory, and the processor is used to store instructions. When the instructions are executed by the processor, the computing device cluster performs the method according to any one of claims 1 to 8.

19. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed, the computer is caused to perform the method according to any one of claims 1 to 8.

20. A computer program product, comprising instructions, characterized in that: When the instructions are executed, the computer implements the method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Multi-threaded concurrent access method and apparatus

    EP4726550A1

  • Multi-threaded concurrent access method and apparatus

    WO2025001238A1