Visual studio feeds

All Visual Studio blogs in one place

Subscribe

Enter your email address:

Delivered by FeedBurner

Increase your website traffic with Attracta.com

Google+

Contact

Email:
Subject:
Message:
Anti-spam: How many eyes has a typical person?

Follow us on FB

Search

Inside the Concurrent Collections: ConcurrentQueue

AddThis Social Bookmark Button
ConcurrentQueue is, like ConcurrentStack, a lockless collection, in that it is implemented without using any locks at all. However, the semantics required for a queue impose a quite different approach; unlike ConcurrentStack, which has a single point of concurrent contention, a queue can be changed at both the head and tail. This means that at least two variables are involved, most likely more. The simple approach of atomically modifying a single variable won't work here. What does System.Collections.Generic.Queue do? Well, let's have a look at the non-concurrent queue. This is implemented as a circular buffer. However, this design is very hard
to use in a lockless way; when a new item is enqueued and the backing array is full, the array is doubled in size to accommodate the new item. To resize the array, the entire contents of the queue has to be read sequentially without using locks and copied into a brand new array by a single thread, during which other threads can enqueue and dequeue items many times. This is very tricky to implement without being subject to race conditions and still ensure high performance. So, instead, ConcurrentQueue forgoes the circular buffer, and uses a linear array instead. More specifically, it...(Read whole news on source site)

Home : Blog List : Simon Cooper : Inside the Concurrent Collections: ConcurrentQueue