Threadsafe FIFO Queue/Buffer

前端 未结 5 1430
无人及你
无人及你 2020-12-18 00:55

I need to implement a sort of task buffer. Basic requirements are:

  • Process tasks in a single background thread
  • Receive tasks from multiple threads
5条回答
  •  别那么骄傲
    2020-12-18 01:33

    Look at my lightweight implementation of threadsafe FIFO queue, its a non-blocking synchronisation tool that uses threadpool - better than create own threads in most cases, and than using blocking sync tools as locks and mutexes. https://github.com/Gentlee/SerialQueue

    Usage:

    var queue = new SerialQueue();
    var result = await queue.Enqueue(() => /* code to synchronize */);
    

提交回复
热议问题