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.