Skip to content

hayabusa-cloud/concurrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

concurrent

Go Reference Go Report Card Coverage Status License: MIT

Concurrent is a library of lock-free and wait-free algorithms

Environment Requirements

  • amd64 or arm64 CPU architecture
  • Go 1.25 or later

Installation

To install the concurrent library, run the following command:

go get code.hybscloud.com/concurrent

Basic Usages

Queue (Convenience Constructor)

c, p := concurrent.NewQueue[string](256)
message := "Hello, Concurrent!"
err := concurrent.EnqueueWait(p, &message)
if err != nil {
	return err
}

result, err := concurrent.DequeueWait(c)
if err != nil {
	return err
}
println(*result)

Multi-Producer Multi-Consumer Queue

c, p := concurrent.NewMPMCQueue[int](256)
i := 100
err := p.Enqueue(&i)
if err != nil {
	return err
}

res, err := c.Dequeue()
if err != nil {
	return err
}
println(*res)

Multi-Producer Multi-Consumer Queue (Indirect)

c, p := concurrent.NewMPMCQueueIndirect(256)
index := uintptr(42)
err := p.Enqueue(index)
if err != nil {
	return err
}

value, err := c.Dequeue()
if err != nil {
	return err
}
println(value)

Spin Lock

lock := concurrent.SpinLock{} // the zero value is ready to use
lock.Lock()
...
lock.Unlock()

Spin Wait

sw := concurrent.SpinWait{} // the zero value is ready to use
sw.Once()

Next Step

Implement the sCQ lock-free FIFO queue

References

License

©2023 Hayabusa Cloud Co., Ltd.
#5F Eclat BLDG, 3-6-2 Shibuya, Shibuya City, Tokyo 150-0002, Japan
Released under the MIT license

About

Go lock-free concurrent algorithms library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published