You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ikopylov edited this page Apr 12, 2017
·
6 revisions
Qoollo BlockingQueue<T>
BlockingQueue<T> is a thread-safe queue with limited capacity and blocking. It is similar to standard BlockingCollection<T> with queue inside, but take advantage of SemaphoreLight. So the BlockingQueue<T> works up to 5 times faster, especially in heavy load scenarios. Also BlockingQueue<T> has several interesting additional methods.
Sample code:
// Create queuevarqueue=newBlockingQueue<int>(boundedCapacity:100);intitem=0;// Enqueue then Dequeuequeue.Add(1);item=queue.Take();// Peek methods supportedif(queue.TryPeek(outitem))Console.WriteLine(item);// Allow to add element even if bouned capacity reachedqueue.AddForced(100);// You can change capacity in runtimequeue.IncreaseBoundedCapacity(1);queue.DecreaseBoundedCapacity(1);// Dispose queuequeue.Dispose();
Performance
All tests performed on CPU with 8 cores. Every iteration has pause for 10 processor ticks (Thread.Spin(10)).