Skip to content

Go implementation of a FIFO, lock-free, concurrent, multi-producer/single-consumer, linked-list-based queue

License

Notifications You must be signed in to change notification settings

ssgreg/funnelqueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()
}

About

Go implementation of a FIFO, lock-free, concurrent, multi-producer/single-consumer, linked-list-based queue

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages