LFE(lock-free extensions) is a library that contains two thread-safe and same time lock-free collections for patterns "multiple producers one consumer" and handling some data parallel.
Initialize the box and share reference between producers and the consumer:
var box = new InputBox<int>();
A producer can looks like:
var val = ReadValue();
while (!box.TryAdd(val)){}
A consumer can looks like:
var values = box.TakeAll()
HandleValues(values);
Initialize the box with data for handling:
var box = new OutputBox(someData);
Spawn several workers like that:
while (box.HasItems)
{
if (box.TryTake(out var item))
HandleItem(item);
}