Is there a lock-free & thread-safe data structure that implements IList?
Naturally by lock-free I mean an implementation that makes no use of locking primitives in .NET but rather uses interlocked operations / atomic operations to achieve thread safety... There isn't one, apparently under the concurrent data structures...
Has anyone seen one floating around?
I've seen a java one implemented in amino-cbbs, called LockFreeVector but nothing for .NET so far. Any ideas?
Well, I couldn't find such a class anywhere; so I gave it a shot.
The source code for my
ConcurrentList<T>
class is available on GitHub.It is lock-free, thread-safe (I think, based on my unit tests), and implements
IList<T>
.It does not support
Insert
,RemoveAt
/Remove
, orClear
.I was pleased to discover that my implementation (which I came up with independently) is very similar to that of a data structure published by some well-respected minds within the world of software.
For a fairly brief discussion of the implementation itself, see my recent blog post about it.
At the moment, it is not documented at all, which is kind of bad considering how "tricky" some of the code is :(
And by all means, rip me a new one if you take a look and find bugs or other issues.
Anyway, it might be worth your time to check it out. If you do, let me know what you think.