Jump to content

Queue/Usage: Difference between revisions

m
m (→‎version 1: removed superflous blanks. -- ~~~~)
Line 460:
=={{header|Go}}==
===With Queue/Definition code===
Solution using [http:[Queue//rosettacode.org/wiki/QueueDefinition#Go |package]] from the [http://rosettacode.org/wiki/Queue [Queue/Definition]] task]:
<lang go>package main
 
Line 513:
green popped
</pre>
 
===With channels===
Go buffered channels are FIFO, and better, are concurrency-safe (if you have an application for that.) Code below is same as code above only with Go channels rather than the home made queue implementation. Note that you don't have to start concurrent goroutines to use channels, they are useful all on their own. Other differences worth noting: Buffered channels are not dynamically resizable. This is a good thing, as queues that can grow without limit allow ugly bugs that consume memory and grind to a halt. Also blocking operations (as seen here with push) are probably a bad idea with a single goroutine. Much safer to use non-blocking operations that handle success and failure (the way pop is done here.)
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.