Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock free stack and queue in C#

Does anyone know if there are any lock-free container libraries available for .NET ?

Preferably something that is proven to work and faster than the Synchronized wrappers we have in .NET.

I have found some articles on the .NET, but none of them specify any speed benchmarking, nor do they inspire much confidence in their reliability.

Thanks

like image 272
Radu094 Avatar asked Feb 15 '09 09:02

Radu094


People also ask

What is lock-free stack?

Stacks make for a simple case study, since the operations on stacks are very simple. The basic principle behind the implementation is that a thread will create a new version of the top of the stack and if no other thread has modified the stack, the change will be made public.

What is a lock-free queue?

Lock-free queue is a queue applying to concurrency but without locking. When using lock-free queue, slow or stopped processes do not prevent other processes from accessing data in it. Lock-free queue has two main interfaces just like normal queue: Enqueue.

Is lock-free always faster?

"For certain workloads" could also be interpreted as "for those workloads that can be synchronized with a lock free data structure". In other words they are always faster, but cannot be always applied.

What does lock-free mean in C++?

lock-free usually doesn't mean "any lock", it means something like transactional memory, or optimistic design, where you don't use lock for every operation, but once in a while (for rolling back or doing transaction) - some kind of lock will be needed.


1 Answers

Late, but better than never I thought I would add Julian Bucknalls articles to this list.

But he does not have performance numbers. In my testing of his structures the list scaled well compared to locking (very low kernel usage compared to ReaderWriterLock).

His blog has a series of articles on lock free structures in C#.

LOCK-FREE DATA STRUCTURES: THE STACK

like image 87
Jason Short Avatar answered Sep 28 '22 02:09

Jason Short