sync

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFloat32

func AddFloat32(addr *float32, delta float32) (new float32)

func AddFloat64

func AddFloat64(addr *float64, delta float64) (new float64)

AddFloat64 add delta to given address atomically

func NewSafeMap

func NewSafeMap() *safeMap

Types

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue implements lock-free FIFO freelist based queue. ref: https://dl.acm.org/citation.cfm?doid=248052.248106

Example
q := NewQueue()

q.Enqueue("1st item")
q.Enqueue("2nd item")
q.Enqueue("3rd item")

fmt.Println(q.Dequeue())
fmt.Println(q.Dequeue())
fmt.Println(q.Dequeue())
Output:

1st item
2nd item
3rd item

func NewQueue

func NewQueue() *Queue

NewQueue creates a new lock-free queue.

func (*Queue) Dequeue

func (q *Queue) Dequeue() interface{}

Dequeue removes and returns the value at the head of the queue. It returns nil if the queue is empty.

func (*Queue) Enqueue

func (q *Queue) Enqueue(v interface{})

Enqueue puts the given value v at the tail of the queue.

func (*Queue) Length

func (q *Queue) Length() uint64

Length returns the length of the queue.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack implements lock-free freelist based stack.

Example
s := NewStack()

s.Push(1)
s.Push(2)
s.Push(3)

fmt.Println(s.Pop())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
Output:

3
2
1

func NewStack

func NewStack() *Stack

NewStack creates a new lock-free queue.

func (*Stack) Pop

func (s *Stack) Pop() interface{}

Pop pops value from the top of the stack.

func (*Stack) Push

func (s *Stack) Push(v interface{})

Push pushes a value on top of the stack.

Jump to

Keyboard shortcuts

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