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

Setting up PQueue to do proper locking by some minor refactoring #6

Closed deckarep closed 10 years ago

deckarep commented 10 years ago

Please review this patch. Since Go locks are not re-entrant, I most likely ran into the same problem you did with having Size() have a read lock. The solution is to have an internal size() method that doesn't lock and provide a public Size() method with the RLock on it. This way, all the other methods can check the internal size() method and we don't have to worry about re-entrancy issues. Please review this, but I think it looks good.

oleiade commented 10 years ago

:+1: Thanks! :)