Last time we implemented an async-compatible producer/consumer queue using portable async-ready synchronization primitives. This time, we’ll give up some of that portability but increase flexibility: we’ll build an async-compatible producer/consumer collection that can be used as a queue (FIFO), stack (LIFO), or bag (unordered).
Actually, it’s pretty simple. It’s almost exactly like our last implementation, which wrapped a Queue. This time, we wrap an IProducerConsumerCollection:
Now we have an AsyncCollection that can be used as a front for many different kinds of collections.
Update (2014-12-01): For more details, see Recipe 8.9 in my Concurrency Cookbook.
About Stephen Cleary
Stephen Cleary is a Christian, husband, father, and programmer living in Northern Michigan.