Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 1 KB

README.md

File metadata and controls

41 lines (32 loc) · 1 KB

codecov Build and test

Oxffaa.LFE

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.

InputBox or multiple producers to one consumer

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);

OutputBox or handling some data parallel

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);
}