funnelqueue

package module
v0.0.0-...-43ccbc7 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 3 Imported by: 0

README

Funnel Queue

GoDoc Build Status Go Report Status

Package funnelqueue implements a FIFO, lock-free, concurrent, multi-producer/single-consumer, linked-list-based queue.

Example

package main

import (
    "fmt"
    "math/rand"
    "runtime"
    "sync"
    "github.com/ssgreg/funnelqueue"
)

func main() {
    n := 10
    wg := sync.WaitGroup{}
    wg.Add(n + 1)
    // make 100 random numbers (per 10 in each 10 goroutines)
    q := funnelqueue.New()
    for i := 0; i < n; i++ {
        go func(i int) {
            defer wg.Done()
            for j := 0; j < n; j++ {
                q.Push(rand.Int() % 64)
            }
        }(i)
    }
    // read these numbers concurrently
    go func() {
        runtime.Gosched()
        defer wg.Done()
        for {
            v := q.Pop()
            if v == nil {
                break
            }
            fmt.Print(v, " ")
        }
    }()
    wg.Wait()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Intrusive

type Intrusive interface {
	Next() *unsafe.Pointer
}

Intrusive declares an interface for an intrusive node.

type IntrusiveNode

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

IntrusiveNode default implementation of Intrusive.

func (*IntrusiveNode) Next

func (d *IntrusiveNode) Next() *unsafe.Pointer

Next returns a pointer to the next object.

type Queue

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

Queue is a FIFO, lock-free, concurrent, multi-producer/single-consumer, linked-list-based queue.

func New

func New() Queue

New creates a new Queue instance.

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

IsEmpty checks if the queue is empty.

IsEmpty can not be used concurrently.

func (*Queue) Pop

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

Pop removes the top value from the queue and returns it as a result of the function call.

Pop can not be used concurrently.

func (*Queue) Push

func (q *Queue) Push(v interface{}) bool

Push adds a value to the end of the queue.

It's allowed to use Push concurrently from different goroutines.

func (*Queue) PushIntrusive

func (q *Queue) PushIntrusive(v Intrusive) bool

PushIntrusive adds a value to the end of the queue. No additional allocations performed in compare of Push.

It's allowed to use Push concurrently from different goroutines.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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