Skip to content

ConcurrentQueue

Parameters

[DType, AddMutex = Nil, PopMutex = Nil; block_size = 64] 

This is a high performance concurrent queue that internally uses a circular linked list of ring buffers to store the items. Concurrent add and pop to and from this queue only take a few nano seconds on modern hardware. You can concurrently add and pop items from different threads. In addition you can choose to install mutexes for add and pop operations separately to enable adding and removing items from more than one thread each.

Type parameters:

  • DType type of the item in the queue
  • AddMutex The mutex to use for the add method (is Nil by default).
  • PopMutex The mutex to use for the pop method (is Nil by default).

const expression params:

  • block_size the size of each circular buffer.
graph BT
N1["ConcurrentQueue[DType,AddMutex,PopMutex; block_size]"] -->|inherits| N2["Length"];

Characteristics

Quality Value
Inherits Length
Extends N/A
Decorators #sealed; #Gambol.layout.c;
Is enum false
Is sealed true
Is extern false

Const Expressions

kMinBlocks

const! kMinBlocks = 4 NInt

Methods

construct

construct (s Self) -> Self

add

add (s Self, item @DType) -> Nil
add an item to the queue. Multiple threads are safe to add at the same time only if an AddMutex is provided


pop_wait_for

pop_wait_for (s Self, wait_for Time) -> DType?
this is the same as pop but if an item is not available it'll wait for a certain period of time before giving up


pop_wait_until

pop_wait_until (s Self, wait_until Time) -> DType?
this is the same as pop but if an item is not available it'll wait util a certain point in time before giving up


pop

pop (s Self, blocking Bool = true) -> DType?
Pops an item off the queue. Multiple threads are safe to pop at the same time only if a PopMutex is provided. If an item does not exist in the queue will return Nil or will block. parameters: * blocking determines if pop is a blocking operation which blocks the thread calling pop until an item becomes available.


len

#strict
len (s Self) -> Len
Will return approximately the number of items on the queue. It is same to call concurrently.


peek

peek (s Self) -> @DType?
will return the head of the queue if there is an item in the queue. If not will return Nil.


__inner_add

__inner_add (s Self, item @DType) -> Nil

__inner_pop

__inner_pop (s Self, result_ptr PointerToVariable[DType?]) -> Bool

Properties

__tail_block

__tail_block Pointer

__empty1

__empty1 Int512

__head_block

__head_block Pointer

__empty2

__empty2 Int512

__block_type_ptr

__block_type_ptr PointerToTypeDefinition[QueueBlock__[DType, block_size]]

__free_blocks

__free_blocks NInt

__used_blocks

__used_blocks NInt

__sem

__sem Semaphore

__empty3

__empty3 Int512

__add_mutex

__add_mutex AddMutex

__empty4

__empty4 Int512

__pop_mutex

__pop_mutex PopMutex