Lock-Free Semaphore Acquisition Using Atomic Operators
Find Innovative SolutionsGenerate 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
Engineering 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
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.
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.
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
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.
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.
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
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.
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.
Data Source
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.


