# US 11,119,832 B2 · Method and device for implementing read-write lock reentry, terminal and storage medium

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 11,119,832 B2
- Document ID: US11119832B2
- Status: Granted
- Kind: B2
- Application number: 16/552,340
- Filed: 2019-08-27
- Published: 2020-03-05
- Granted: 2021-09-14
- Earliest claimed: 2018-08-28
- Assignees: Baidu Online Network Technology (Beijing) Co., Ltd.
- Applicants: Baidu Online Network Technology (Beijing) Co., Ltd.
- Inventors: Kaiwen Feng; Zhuo Chen; Yuedong Dang; Ronggui Peng; Wanyu Bao; Zhongjun Ni
- Web page: https://patentgrep.com/patent/US11119832B2

## CPC

- G06F 9/524: {Deadlock detection or avoidance}
- G06F 9/526: {Mutual exclusion algorithms}
- G06F 9/5005: {to service a request}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The embodiments of the present disclosure provide a method and a device for implementing read-write lock reentry, a terminal and a storage medium. The method includes: receiving a write lock request of a thread to a target resource; in response to determining that the target resource is in a write-lock-exclusive state, acquiring a historical write-lock thread to the target resource that is in the write-lock-exclusive state; in response to determining that the thread is identical to the historical write-lock thread, adding a new lock of the thread to the target resource.

## Claims

### Claim 1

A method for implementing read-write lock reentry, comprising:
receiving a lock request of a thread to a target resource;
in response to determining that the target resource is in a write-lock-exclusive state, acquiring a historical write-lock thread to the target resource that is in the write-lock-exclusive state;
in response to determining that the target resource is in an unlocked state, adding a write lock of the thread to the target resource and taking the thread as a write-lock thread to the target resource under as case that the lock request is a write-lock request, and adding a read lock of the thread to the target resource and taking the thread as a read-lock thread to the target resource under a case that the lock request is a read-lock request;
in response to determining that ID of the thread is identical to ID of the historical write-lock thread, adding a new lock of the thread to the target resource; and
in response to determining that the ID of thread is different from the ID of the historical write-lock thread, rejecting the lock request of the thread.

### Claim 2 (depends on 1)

The method according to claim 1, after adding the new lock of the thread to the target resource, further comprising:
in response to detecting that all locks of the target resource are unlocked, determining that the target resource is in an unlocked state.

### Claim 3 (depends on 1)

The method according to claim 1, after adding the new lock of the thread to the target resource, further comprising:
receiving and responding to an access instruction of the thread to the target resource.

### Claim 4

A terminal, comprising:
one or more processors;
a storage device, configured to store one or more programs; and
wherein, when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement a method for implementing read-write lock reentry, the method comprising:
receiving a lock request of a thread to a target resource;
in response to determining that the target resource is in a write-lock-exclusive state, acquiring a historical write-lock thread to the target resource that is in the write-lock-exclusive state;
in response to determining that the target resource is in an unlocked state, adding a write lock of the thread to the target resource and taking the thread as a write-lock thread to the target resource under as case that the lock request is a write-lock request, and adding a read lock of the thread to the target resource and taking the thread as a read-lock thread to the target resource under a case that the lock request is a read-lock request;
in response to determining that ID of the thread is identical to ID of the historical write-lock thread, adding a new lock of the thread to the target resource; and
in response to determining that the ID of thread is different from the ID of the historical write-lock thread, rejecting the lock request of the thread.

### Claim 5 (depends on 4)

The terminal according to claim 4, after adding the new lock of the thread to the target resource, further comprising:
in response to detecting that all locks of the target resource are unlocked, determining that the target resource is in an unlocked state.

### Claim 6 (depends on 4)

The terminal according to claim 4, after adding the new lock of the thread to the target resource, further comprising:
receiving and responding to an access instruction of the thread to the target resource.

### Claim 7

A non-transitory storage medium having computer programs stored thereon, wherein when the programs are executed by a processor, a method for implementing read-write lock reentry is implemented, the method comprising:
receiving a lock request of a thread to a target resource;
in response to determining that the target resource is in a write-lock-exclusive state, acquiring a historical write-lock thread to the target resource that is in the write-lock-exclusive state;
in response to determining that the target resource is in an unlocked state, adding a write lock of the thread to the target resource and taking the thread as a write-lock thread to the target resource under as case that the lock request is a write-lock request, and adding a read lock of the thread to the target resource and taking the thread as a read-lock thread to the target resource under a case that the lock request is a read-lock request;
in response to determining that ID of the thread is identical to ID of the historical write-lock thread, adding a new lock of the thread to the target resource; and
in response to determining that the ID of thread is different from the ID of the historical write-lock thread, rejecting the lock request of the thread.

### Claim 8 (depends on 7)

The non-transitory storage medium according to claim 7, after adding the new lock of the thread to the target resource, further comprising:
in response to detecting that all locks of the target resource are unlocked, determining that the target resource is in an unlocked state.

### Claim 9 (depends on 7)

The non-transitory storage medium according to claim 7, after adding the new lock of the thread to the target resource, further comprising:
receiving and responding to an access instruction of the thread to the target resource.
