Lock-Free Semaphore Acquisition Using Atomic Operators

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional semaphores in operating systems face issues with deadlocks and misallocation of resources due to the use of locks and non-deterministic atomic operators, which can lead to increased complexity and unpredictability in system runtime.

Innovation Solution

A method for acquiring and releasing semaphores that utilizes deterministic atomic operators, eliminating the need for locks and non-deterministic operators by decrementing and incrementing a semaphore count, managing pending threads through a queue, and scheduling tasks without spinlocks or atomic operators.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If locks are used to isolate the semaphore for a process, then resource allocation control is improved, but deadlocks and system impasses occur preventing semaphore acquisition

Engineering Contradiction:
Improveresource allocation controlVSAvoidsemaphore acquisition
Core Design Contradiction:
ReliabilityVSProductivity

Solution Approach 1:

The patent extracts the locking mechanism from the semaphore acquisition and release operations. Instead of using locks to isolate the semaphore, the invention uses atomic operators that inherently provide the necessary isolation without requiring external locking mechanisms. This eliminates deadlocks while maintaining resource allocation control.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent replaces the mechanical locking system with atomic operators provided by the processor architecture. These atomic operators (such as compare-and-swap, test-and-set, or atomic read-modify-write operations) provide the necessary mutual exclusion through hardware-level atomicity rather than software-based locks, thereby preventing deadlocks.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

2Device complexity

If non-deterministic atomic operators are used for semaphore operations, then resource allocation is simplified, but the run-time of the system cannot be bounded and complexity increases

Engineering Contradiction:
Improvesemaphore operation complexityVSAvoidsystem run-time
Core Design Contradiction:
Device complexityVSDuration of action of moving object

Solution Approach 1:

The patent introduces a deterministic structure to semaphore operations by using a bounded waiting mechanism. The system periodically checks the semaphore state in a controlled manner, ensuring that the number of iterations is bounded. This allows the run-time to be predictable while maintaining simplicity in the atomic operations used.

Inventive Principle:
Principle #19Periodic action

Solution Approach 2:

The patent changes the parameters of the atomic operators used to ensure determinism. By selecting specific atomic operations with known, bounded execution characteristics and controlling the number of retries through a deterministic algorithm, the system achieves both simplicity and predictable run-time behavior.

Inventive Principle:
Principle #35Parameter changes

3Reliability

If complex lock-free algorithms are used to avoid deadlocks, then semaphore acquisition reliability is improved, but the algorithms are difficult to prove correct resulting in resource misallocation

Engineering Contradiction:
Improvedeadlock preventionVSAvoidalgorithm correctness verification
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent uses a simplified copy of the semaphore state that can be safely read without locking. By maintaining a consistent view of the semaphore state through atomic operations and using a straightforward queue structure for pending threads, the algorithm becomes easier to verify correct while still preventing deadlocks.

Inventive Principle:
Principle #26Copying

Solution Approach 2:

The patent implements a self-service mechanism where threads can independently determine their status and proceed with acquisition or release operations using simple atomic operators. The algorithm does not require complex coordination or verification mechanisms because each thread autonomously manages its own semaphore interaction through well-defined atomic operations.

Inventive Principle:
Principle #25Self-service

Data Source

PatentUS9342379B2Lock free acquisition and release of a semaphore in a multi-core processor environment
Publication Date: 2016.05.17 WIND RIVER SYSTEMS INC
  • US9342379B2 patent drawing
  • US9342379B2 patent drawing
  • US9342379B2 patent drawing

AI summary

A method for an acquisition of a semaphore for a thread includes decrementing a semaphore count, storing a current thread context of the semaphore when the semaphore count is less than a first predetermined value, determining a release count of a pending queue associated with the semaphore where the pending queue indicates unpended threads of the semaphore, and adding the thread to the pending queue when the release count is less than a second predetermined value.