# US 2019/0317832 A1 · Fast thread wake-up through early lock release

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

- Number: US 2019/0317832 A1
- Document ID: US20190317832A1
- Status: Published application
- Kind: A1
- Application number: 15/952,143
- Filed: 2018-04-12
- Published: 2019-10-17
- Earliest claimed: 2018-04-12
- Assignees: Advanced Micro Devices, Inc.
- Applicants: Advanced Micro Devices, Inc.
- Inventors: Nuwan Jayasena; Amin Farmahini-Farahani; David A. Roberts
- Web page: https://patentgrep.com/patent/US20190317832A1

## CPC

- G06F 9/52: Program synchronisation; Mutual exclusion, e.g. by means of semaphores
- G06F 9/48: Program initiating; Program switching, e.g. by interrupt
- G06F 9/4806: {Task transfer initiation or dispatching}
- G06F 9/4843: {by program, e.g. task dispatcher, supervisor, operating system}
- G06F 9/485: {Task life-cycle, e.g. stopping, restarting, resuming execution (G06F9/4881 takes precedence)}
- G06F 9/50: Allocation of resources, e.g. of the central processing unit [CPU]
- G06F 9/5005: {to service a request}
- G06F 9/5011: {the resources being hardware resources other than CPUs, Servers and Terminals}
- G06F 9/522: {Barrier synchronisation}
- G06F 9/526: {Mutual exclusion algorithms}
- G06F 9/528: {by using speculative mechanisms}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A thread holding a lock notifies a sleeping thread that is waiting on the lock that the lock holding thread is “about” to release the lock. In response to the notification, the waiting thread is woken up. While the waiting thread is woken up, the lock holding thread completes other operations prior to actually releasing the lock and then releases the lock. The notification to the waiting thread hides latency associated with waking up the waiting thread by allowing operations that wake up the waiting thread to occur while the lock holding thread is performing the other operations prior to releasing the thread.

## Claims

### Claim 1

A method for releasing a thread synchronization lock and waking up a waiting thread, the method comprising:
performing a first pre-release operation by a lock holder thread to notify the waiting thread that the thread synchronization lock is pending release;
responsive to the first pre-release operation, initiating wake-up of the waiting thread;
performing one or more operations before lock release for the lock holder thread in a first time period that at least partially overlaps with a second time period during which the waiting thread wakes up;
responsive to the one or more operations before lock release ending, performing a lock release operation by the lock holder thread; and
responsive to the lock release operation, continuing execution of the waiting thread past the lock.

### Claim 2 (depends on 1)

The method of claim 1, wherein the first pre-release operation is performed in response to executing a pre-release instruction that is part of an instruction set architecture of a processor on which the lock holder thread is executing.

### Claim 3 (depends on 1)

The method of claim 1, further comprising:
switching off operating system thread pre-emption from the time that the first pre-release operation is performed until the time that the lock release operation is performed.

### Claim 4 (depends on 1)

The method of claim 1, wherein:
after the waiting thread wakes up, the waiting thread checks the lock, determines that the lock release operation has occurred and continues execution upon determining that the lock release operation has occurred.

### Claim 5 (depends on 4)

The method of claim 4, wherein checking the lock comprises:
determining that the lock is not available but that the lock is marked as pre-released; and
responsive to the determining, polling the lock.

### Claim 6 (depends on 5)

The method of claim 5, further comprising:
performing the polling until a timeout has occurred; and
responsive to the timeout occurring, putting the waiting thread to sleep.

### Claim 7 (depends on 6)

The method of claim 6, further comprising:
responsive to the timeout occurring, marking the lock as not pre-released.

### Claim 8 (depends on 1)

The method of claim 1, further comprising:
after waking up the waiting thread, attempting to acquire the lock by the waiting thread; and
upon not being able to acquire the lock but determining that the pre-release operation has been performed for the lock, polling the lock by the waiting thread, instead of putting the waiting thread to sleep.

### Claim 9 (depends on 8)

The method of claim 8, further comprising:
after a timeout has occurred during which the thread synchronization lock is polled, putting the waiting thread to sleep.

### Claim 10

A system for releasing a thread synchronization lock and waking up a waiting thread, the system comprising:
a first device configured to execute a lock holder thread; and
a second device configured to execute a waiting thread, the second device being either the first device or a device that is not the first device,
wherein the lock holder thread is configured to:
perform a first pre-release operation to notify the waiting thread that the thread synchronization lock is pending release,
perform one or more operations before lock release for the lock holder thread in a first time period that at least partially overlaps with a second time period, and responsive to the one or more operations before lock release ending, perform a lock release operation;
wherein the waiting thread is configured to:
responsive to the pre-release operation, initiate wake-up of the waiting thread during the second time period, and
responsive to the lock release operation, continue execution of the waiting thread past the lock.

### Claim 11 (depends on 10)

The system of claim 10, wherein the pre-release operation is performed in response to executing a pre-release instruction that is part of an instruction set architecture of the first device.

### Claim 12 (depends on 10)

The system of claim 10, wherein an operating system is configured to switch off operating system thread pre-emption from the time that the first pre-release operation is performed.

### Claim 13 (depends on 10)

The system of claim 10, wherein after the waiting thread wakes up, the waiting thread is further configured to:
check the lock and determine that the lock release operation has occurred and continue execution upon determining that the lock release operation has occurred.

### Claim 14 (depends on 13)

The system of claim 13, wherein the waiting thread is configured to check the lock by:
determining that the lock is not available but that the lock is marked as pre-released; and
responsive to the determining, polling the lock.

### Claim 15 (depends on 14)

The system of claim 14, wherein the waiting thread is further configured to:
perform the polling until a timeout has occurred; and
responsive to the timeout occurring, putting the waiting thread to sleep.

### Claim 16 (depends on 15)

The system of claim 15, wherein the waiting thread is further configured to, responsive to the timeout occurring, mark the lock as not pre-released.

### Claim 17 (depends on 10)

The system of claim 10, wherein:
the waiting thread is configured to, after waking up, attempt to acquire the thread synchronization lock; and
upon not being able to acquire the lock but determining that the pre-release operation has been performed for the lock, poll the lock instead of putting the waiting thread to sleep.

### Claim 18 (depends on 10)

The system of claim 10, wherein the waiting thread is further configured to, after a timeout has occurred during which the thread synchronization lock is polled, put the waiting thread to sleep.

### Claim 19

A non-transitory computer-readable medium storing instructions for releasing a thread synchronization lock and waking up a waiting thread, that when executed by a processor, cause the processor to:
perform a first pre-release operation by a lock holder thread to notify the waiting thread that the thread synchronization lock is pending release;
responsive to the first pre-release operation, initiate wake-up of the waiting thread;
perform one or more operations before lock release for the lock holder thread in a first time period that at least partially overlaps with a second time period during which the waiting thread wakes up;
responsive to the one or more operations before lock release ending, perform a lock release operation by the lock holder thread; and
responsive to the lock release operation, continue execution of the waiting thread past the lock.

### Claim 20 (depends on 19)

The non-transitory computer-readable medium of claim 19, wherein the first pre-release operation is performed in response to executing a pre-release instruction that is part of an instruction set architecture of a processor on which the lock holder thread is executing.
