Thread-safe collection types that fill gaps in the standard library. Includes ConcurrentList<T>, a thread-safe IList<T> implementation with indexed access, enumeration, and reader-writer lock semantics for efficient concurrent operations.
$ dotnet add package Baubit.CollectionsThread-safe collection types that fill gaps in the standard library.
I needed a thread-safe list with indexed access and enumeration support. ConcurrentBag<T> doesn't provide ordering or indexing, and List<T> with manual locking is error-prone. So I built ConcurrentList<T>.
A thread-safe IList<T> implementation using ReaderWriterLockSlim for efficient concurrent reads with exclusive writes.
var list = new ConcurrentList<int>();
// Multiple threads can read simultaneously
Parallel.For(0, 100, i => {
var count = list.Count;
var item = list[0];
});
// Writes are exclusive and thread-safe
Parallel.For(0, 100, i => list.Add(i));
// Safe enumeration (uses snapshot)
foreach (var item in list) {
list.Add(999); // Won't affect the enumeration
}
dotnet add package Baubit.Collections
More collections coming as needed. MIT Licensed.