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

Copy/Contents of Methods #13

Open stephen304 opened 9 years ago

stephen304 commented 9 years ago

I'd like to use lane to store a variable list of things where the oldest items are only the ones being removed and the newest go in front. Naturally, a queue from this package would work great, but when printing the contents of the queue, you have to destroy it by popping everything off. This makes my brain hurt when trying to figure out whether I can safely print the contents this way while another thread may be writing to the queue, as the locks are per operation (pop), and there's no way to lock the list for the duration of the copy process.

I would like to propose one of two things:

What do you think?

oleiade commented 8 years ago

Hey @stephen304

First of all, sorry for the looooooonnng reply delay :-)

That's an interesting point!

Talking about this, I realize it might be a good idea to add a Lock and Unlock methods to the data structures. That would probably ease the interactions with the structs in concurrent algorithm context!