Help us shape the future of Go! Take the 2026 Go Developer Survey

lockfree

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 3 Imported by: 0

README

lockfree

GoDoc Build Status Go Report Card codecov

Package lockfree offers lock-free utilities in Go.

Contributing

We would love to have your experiences. Feel free to submit an issue for requesting new implementation or bug report.

License

MIT © Changkun Ou

Documentation

Overview

Package lockfree offers lock-free utilities

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFloat64

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

AddFloat64 add delta to given address atomically

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
package main

import (
	"fmt"

	"github.com/changkun/lockfree"
)

func main() {
	q := lockfree.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
package main

import (
	"fmt"

	"github.com/changkun/lockfree"
)

func main() {
	s := lockfree.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