oleiade / lane

Generic PriorityQueues, Queues, Stacks, and Deque data structures for Go
https://pkg.go.dev/github.com/oleiade/lane#pkg-types
MIT License
878 stars 76 forks source link

Strange queue behaviour #11

Closed sashabaranov closed 8 years ago

sashabaranov commented 9 years ago

I tried this code sample based on README:

package main

import "fmt"
import "github.com/oleiade/lane"
import "runtime"

func main() {
    // runtime.GOMAXPROCS(3)

    queue := lane.NewQueue()
    queue.Enqueue("grumpyClient")
    queue.Enqueue("happyClient")
    queue.Enqueue("ecstaticClient")

    // Let's handle the clients asynchronously
    for client := queue.Dequeue(); client != nil; {
        go fmt.Println(client)
    }
}

What I expected from it: should print 3 strings from queue and exit. What actually happens: prints "grumpyClient" lots of times. Removing "go" in loop does not change anything.

Tested on go1.4.1 darwin/amd64(os x 10.9.5) and go1.2.1 linux/amd64(ubuntu precise). Same thing

Uncommenting line with runtime.GOMAXPROCS(3) causes lots of tracebacks on OS X(not on linux).

ivan-mlnn commented 9 years ago

I have some behaviour go version go1.4 windows/386

sashabaranov commented 9 years ago

Library is fine, the problem was in code sample.

oleiade commented 8 years ago

Thanks for the PR @sashabaranov