Thread Lock Status Check to Avoid Context Switching

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

In multithreaded environments, costly context switches occur when a thread waiting on a locked shared resource transitions to sleep, leading to unnecessary resource consumption and inefficiency.

Innovation Solution

An additional check is performed after a thread transitions into the kernel mode but before going to sleep to determine if the lock has been released, allowing the thread to access the resource and avoid context switching.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Loss of energy

If a thread transitions to sleep mode after waiting on a lock, then the thread relinquishes processor control, but a costly context switch occurs consuming processor and operating system resources

Engineering Contradiction:
Improveprocessor and operating system resourcesVSAvoidcontext switching efficiency
Core Design Contradiction:
Loss of energyVSProductivity

Solution Approach 1:

The patent applies preliminary action by performing a lock status check after the thread transitions into kernel mode but before it enters sleep mode. This advance check determines whether the lock has been released during the transition period, allowing the thread to wake up immediately and access the resource without undergoing a costly context switch, thus preventing unnecessary resource consumption

Inventive Principle:
Principle #10Preliminary action

2Reliability

If a thread continuously checks lock status in a loop, then the thread can detect when the lock is released, but the thread consumes processor resources during the waiting period

Engineering Contradiction:
Improvelock acquisition accuracyVSAvoidprocessor resources
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The patent implements periodic action by having the thread check the lock status at specific intervals: first in a spin loop for a predetermined period, then again after transitioning to kernel mode before sleeping. This periodic checking strategy balances reliable lock detection with reduced processor resource consumption compared to continuous checking

Inventive Principle:
Principle #19Periodic action

Solution Approach 2:

The thread performs self-service by autonomously checking the lock status at multiple stages and making its own decision about whether to wake up or continue sleeping, without requiring external intervention from the operating system or other threads

Inventive Principle:
Principle #25Self-service

Data Source

PatentUS9384049B2Preventing unnecessary context switching by employing an indicator associated with a lock on a resource
Publication Date: 2016.07.05 MICROSOFT TECHNOLOGY LICENSING LLC
  • US9384049B2 patent drawing
  • US9384049B2 patent drawing
  • US9384049B2 patent drawing

AI summary

A method of avoiding unnecessary context switching in a multithreaded environment. A thread of execution of a process waiting on a lock protecting access to a shared resource may wait for the lock to be released by executing in a loop, or “spin”. The waiting thread may continuously check, in a user mode of an operating system, an indicator of whether the lock has been released. After a certain time period, the thread may stop spinning and enter a kernel mode of the operating system. Subsequently, before going to sleep which entails costly context switching, the thread may perform an additional check of the indicator to determine whether the lock has been released. If this is the case, the thread returns to user mode and the unnecessary context switching is avoided.