This is an concurrent-queue and concurrent-stack lib for the go.
go get github.com/boobusy/vector
import (
"github.com/boobusy/vector"
)
func main() {
for i := 0; i < 100; i++ {
vector.Push(i)
}
fmt.Println(vector.IsEmpty(),vector.Len(),vector.Cap())
fmt.Println(vector.Items())
for !vector.IsEmpty() {
fmt.Println(vector.PopBack()) // or fmt.Println(vector.PopFront())
}
}
func main() {
var queue *vector.Type = vector.New(10000)
//queue := vector.New(10000)
// auto clean
queue.UsePurge(1<<20, 100 * time.Millisecond)
w := sync.WaitGroup{}
for i := 0; i < 100; i++ {
w.Add(1)
go func() {
defer w.Done()
for k := 0; k < 1000; k++ {
task := &Task{
Id: k,
}
queue.Push(task)
}
}()
}
w.Wait()
fmt.Println(queue.IsEmpty(), queue.Len(), queue.Cap())
var val vector.Val
for !queue.IsEmpty() {
val = queue.PopBack()
fmt.Println(val.(*Task).Id) // or fmt.Println(vector.PopFront())
}
}
问题或者建议联系作者:十二楼五城