twolock

package
v0.0.0-...-6997cb8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package lockfree provides a concurrent blocking livelock-free FIFO queue. Described in https://doi.org/10.1145/248052.248106

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue implements a singly-linked list with a Push and Pop function.

Head always points to a dummy node, so we can assume head is never nil within the dequeue code. Tails always points to the last or second to last node in the list.

This Queue has some properties. See 3.1 to see the proof 1. The linked list is always connected. 2. Nodes are only inserted after the last node in the linked list. 3. Nodes are only deleted from the beginning of the linked list. 4. Head always points to the first node in the linked list. 5. Tail always points to a node in the linked list.

func New

func New[T any]() *Queue[T]

New will return an empty queue.

func (*Queue[T]) Pop

func (queue *Queue[T]) Pop() (value T, ok bool)

Pop will return the next value in the queue, if the queue isn't empty otherwise ok will return false.

func (*Queue[T]) Push

func (queue *Queue[T]) Push(data T)

Push will insert a new value onto the queue.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL