Lock-Free Double-Ended Queue Using DCAS and Ring Buffer

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing lock-free double-ended queues face performance issues due to time-consuming memory allocation and deallocation operations in multi-threaded systems, especially when usage is unbalanced, leading to reduced node reuse and increased memory management overhead.

Innovation Solution

A lock-free double-ended queue implemented as a doubly-linked list forming a ring structure, using double compare-and-swap (DCAS) operations to manage node pointers and dynamically resize the ring by splicing in new segments, allowing for efficient growth and shrinkage without frequent allocation and deallocation, and utilizing special markers for splicing operations.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If dynamic memory allocation and deallocation are performed for each item in a lock-free deque, then the deque can grow and shrink flexibly, but the performance deteriorates due to time-consuming memory management operations

Engineering Contradiction:
Improvedeque growth and shrinkage flexibilityVSAvoidmemory management performance
Core Design Contradiction:
Adaptability or versatilityVSProductivity

Solution Approach 1:

The patent pre-allocates a pool of nodes in advance and stores them in a separate storage structure. When items are pushed onto the deque, pre-allocated nodes are reused instead of performing dynamic allocation operations. This preliminary preparation of resources eliminates the performance penalty of frequent memory allocation and deallocation while maintaining the deque's ability to grow and shrink flexibly.

Inventive Principle:
Principle #10Preliminary action

2Productivity

If a linear data structure is used for bulk allocation, then memory can be reused efficiently when pushes and pops are balanced, but the reuse is reduced when usage is unbalanced as the active portion shifts away from the popping end

Engineering Contradiction:
Improvememory reuse efficiencyVSAvoidhandling of unbalanced usage patterns
Core Design Contradiction:
ProductivityVSAdaptability or versatility

Solution Approach 1:

The patent transforms the linear storage structure into a circular buffer (ring structure). In this circular arrangement, when the deque experiences unbalanced usage patterns, the active portion of the buffer simply rotates around the ring rather than shifting linearly. This curvature allows the same memory region to be reused indefinitely regardless of whether pushes exceed pops or vice versa, maintaining high memory reuse efficiency under all usage patterns.

Inventive Principle:
Principle #14Spheroidality (Curvature)

3Reliability

If locks are used to control access to data structures in a multi-threaded environment, then thread interference is prevented, but processes stall and performance deteriorates

Engineering Contradiction:
Improvethread safetyVSAvoidconcurrent processing performance
Core Design Contradiction:
ReliabilityVSProductivity

Solution Approach 1:

The patent replaces the mechanical locking system with a lock-free algorithm based on atomic operations (compare-and-swap instructions). Instead of using mutexes or semaphores that cause processes to stall when contended, the implementation uses hardware-supported atomic instructions that allow multiple threads to concurrently access and modify the deque without blocking each other, thereby maintaining thread safety while eliminating performance degradation from locking.

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

Data Source

PatentUS7583687B2Lock-free double-ended queue based on a dynamic ring
Publication Date: 2009.09.01 ORACLE AMERICAN INC
  • US7583687B2 patent drawing
  • US7583687B2 patent drawing
  • US7583687B2 patent drawing

AI summary

One embodiment of the present invention provides a system that facilitates performing operations on a lock-free double-ended queue (deque). This deque is implemented as a doubly-linked list of nodes formed into a ring, so that node pointers in one direction form an inner ring, and node pointers in the other direction form an outer ring. The deque has an inner hat, which points to a node next to the last occupied node along the inner ring, and an outer hat, which points to a node next to the last occupied node along the outer ring. The system uses a double compare-and-swap (DCAS) operation while performing pop and push operations onto either end of the deque, as well as growing and shrinking operations to change the number of nodes that are in the ring used by the deque.