# US 2021/0342190 A1 · Versioned progressive chunked queue for a scalable multi-producer and multi-consumer queue

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

- Number: US 2021/0342190 A1
- Document ID: US20210342190A1
- Status: Published application
- Kind: A1
- Application number: 16/863,551
- Filed: 2020-04-30
- Published: 2021-11-04
- Earliest claimed: 2020-04-30
- Assignees: Red Hat, Inc.
- Applicants: Red Hat, Inc.
- Inventors: Francesco Nigro
- Web page: https://patentgrep.com/patent/US20210342190A1

## CPC

- G06F 9/5016: {the resource being the memory}
- G06F 9/544: {Buffers; Shared memory; Pipes}
- G06F 9/4881: {Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues}
- G06F 2209/5013: Request control
- G06F 2209/5018: Thread allocation
- G06F 2209/548: Queue
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method includes receiving, by a producer thread of a plurality of producer threads, an offer request associated with an item. The producer thread increases a sequence and determines (i) a chunk identifier of a memory chunk from a pool of memory chunks and (ii) a first slot position in the memory chunk to offer the item. The producer thread also writes the item into the memory chunk at the first slot position. Then, a first consumer thread of a plurality of consumer threads determines the first slot position of the item and consumes the item at the first slot position. A second consumer thread consumes another item at a second slot position in the memory chunk and recycles the memory chunk.

## Claims

### Claim 1

A method comprising:
receiving, by a producer thread of a plurality of producer threads, an offer request associated with an item;
responsive to receiving the offer request, increasing, by the producer thread, a sequence;
determining, by the producer thread, (i) a chunk identifier, associated with the sequence, of a memory chunk from a pool of memory chunks and (ii) a first slot position, from the sequence, in the memory chunk to offer the item;
writing, by the producer thread, the item into the memory chunk at the first slot position;
determining, by a first consumer thread of a plurality of consumer threads, the first slot position of the item;
consuming, by the first consumer thread, the item at the first slot position;
consuming, by a second consumer thread of the plurality of consumer threads, another item at a second slot position in the memory chunk;
determining, by the second consumer thread, that the memory chunk is recyclable; and
recycling, by the second consumer thread, the memory chunk.

### Claim 2 (depends on 1)

The method of claim 1, further comprising:
receiving, by the first consumer thread, a consume request prior to consuming the item at the first slot position;
reading, by the first consumer thread, a consumer sequence;
reading, by the first consumer thread, a consumer buffer; and
determining, by the first consumer thread, (i) a second chunk identifier associated with the consumer sequence and (ii) a third slot position from the consumer sequence.

### Claim 3 (depends on 1)

The method of claim 1, further comprising writing, by the producer thread, additional items into the memory chunk after the memory chunk has been recycled.

### Claim 4 (depends on 3)

The method of claim 3, further comprising consuming, by the at least one of the first consumer thread and the second consumer thread, the additional items from the memory chunk.

### Claim 5 (depends on 1)

The method of claim 1, further comprising updating, by the producer thread, the sequence responsive to writing the item into the memory chunk at the first slot position.

### Claim 6 (depends on 5)

The method of claim 5, wherein the sequence is one of a consumer sequence and a producer sequence, and the sequence is configured to ensure a sequence of operations between the plurality of producer threads and the plurality of consumer threads is coordinated.

### Claim 7

A system comprising:
a memory configured to store a plurality of memory chunks;
at least one processor configured to execute a plurality of producer threads and a plurality of consumer threads, wherein a producer thread of the plurality of producer threads is configured to:
receive an offer request associated with an item,
responsive to receiving the offer request, increase a sequence,
determine (i) a chunk identifier, associated with the sequence, of a memory chunk from a pool of memory chunks and (ii) a first slot position, from the sequence, in the memory chunk to offer the item, and
write the item into the memory chunk at the first slot position;
wherein a first consumer thread of the plurality of consumer threads is configured to:
consume the item at the first slot position; and
wherein a second consumer thread of the plurality of consumer threads is configured to:
consume another item at a second slot position in the memory chunk,
determine that the memory chunk is recyclable, and
recycle the memory chunk.

### Claim 8 (depends on 7)

The system of claim 7, wherein consuming the second slot includes writing a NULL value into the second slot.

### Claim 9 (depends on 7)

The system of claim 7, wherein the memory chunk includes a plurality of slots, and wherein the plurality of slots is arranged in an array, and each slot of the plurality of slots is associated with a sequence value and an item value.

### Claim 10 (depends on 9)

The system of claim 9, wherein the first consumer thread and the second consumer thread are configured to simultaneously consume respective slots of the plurality of slots.

### Claim 11 (depends on 7)

The system of claim 7, wherein the sequence is a producer sequence that is an array of 64-bit elements.

### Claim 12 (depends on 7)

The system of claim 7, wherein at least one of the plurality of producer threads and the plurality of consumer threads is configured to reallocate the detached memory chunk back to the pool of memory chunks.

### Claim 13 (depends on 7)

The system of claim 7, wherein the producer thread is configured to write additional items into the memory chunk, and wherein at least one of the first consumer thread and the second consumer thread are configured to consume the additional items from the memory chunk.

### Claim 14 (depends on 7)

The system of claim 7, wherein the plurality of memory chunks forms an unbounded queue, and wherein the memory chunk occupies at least two cache-lines.

### Claim 15

A method comprising:
receiving, by a consumer thread of a plurality of consumer threads, a consume request associated with an element;
responsive to receiving the consume request, reading, by the consumer thread, a consumer sequence and a consumer buffer;
extracting, by the consumer thread, (i) a chunk identifier, associated with the consumer sequence and (ii) a slot position in a memory chunk from the consumer sequence;
determining, by the consumer thread, that a position of the element mismatches the slot position in the memory chunk from the consumer sequence;
determining, by the consumer thread, that the memory chunk is recyclable;
increasing, by the consumer thread, the consumer sequence; and
consuming, by the consumer thread, the element at the slot position.

### Claim 16 (depends on 15)

The method of claim 15, further comprising writing, by a producer thread, additional elements into the memory chunk.

### Claim 17 (depends on 16)

The method of claim 16, further comprising consuming, by the consumer thread and a different consumer thread, the additional elements from the memory chunk.

### Claim 18 (depends on 15)

The method of claim 15, wherein consuming the element includes writing a NULL value into the slot position.

### Claim 19 (depends on 15)

The method of claim 15, further comprising:
determining, by the consumer thread, that a second position of the element matches the slot position in the memory chunk from the consumer sequence;
reducing, by the consumer thread, the consumer sequence to a reduced consumer sequence; and
comparing, by the consumer thread, the reduced consumer sequence to the chunk identifier.

### Claim 20 (depends on 15)

The method of claim 15, wherein consuming the element includes writing a NULL value into the slot position.
