queue

package
v1.19.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: LGPL-3.0 Imports: 2 Imported by: 0

README

Overview

Package queue offers goroutine-safe Queue implementations such as LockfreeQueue(Lock free queue).

LockfreeQueue

LockfreeQueue is a goroutine-safe Queue implementation. The overall performance of LockfreeQueue is much better than List+Mutex(standard package).

Basic example

lfq := queue.NewLockfreeQueue[int]() // create a LockfreeQueue
lfq.Push(100) // Push an element into the queue
v, ok := lfq.Pop() // Pop an element from the queue

Documentation

Overview

Package queue offers goroutine-safe Queue implementations such as LockfreeQueue(Lock free queue).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LockfreeQueue

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

LockfreeQueue is a goroutine-safe Queue implementation. The overall performance of LockfreeQueue is much better than List+Mutex(standard package).

func NewLockfreeQueue

func NewLockfreeQueue[T any]() *LockfreeQueue[T]

NewLockfreeQueue is the only way to get a new, ready-to-use LockfreeQueue.

Example:

lfq := queue.NewLockfreeQueue[int]()
lfq.Push(100)
v, ok := lfq.Pop()

func (*LockfreeQueue[T]) Pop

func (lfq *LockfreeQueue[T]) Pop() (T, bool)

Pop returns (and removes) an element from the front of the queue and true if the queue is not empty, otherwise it returns a default value and false if the queue is empty. It performs about 100% better than list.List.Front() and list.List.Remove() with sync.Mutex.

func (*LockfreeQueue[T]) Push

func (lfq *LockfreeQueue[T]) Push(val T)

Push inserts an element to the back of the queue. It performs exactly the same as list.List.PushBack() with sync.Mutex.

Jump to

Keyboard shortcuts

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