SimpleMultithreadQueue 1.0.1

Install-Package SimpleMultithreadQueue -Version 1.0.1
dotnet add package SimpleMultithreadQueue --version 1.0.1
<PackageReference Include="SimpleMultithreadQueue" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleMultithreadQueue --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SimpleMultithreadQueue, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SimpleMultithreadQueue as a Cake Addin
#addin nuget:?package=SimpleMultithreadQueue&version=1.0.1

// Install SimpleMultithreadQueue as a Cake Tool
#tool nuget:?package=SimpleMultithreadQueue&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


Queue for multithread programs with one queue reader and several writers

How it works

MultithreadQueue<T> contains two objects Queue<T> one is an active queue (current queue) and one is a buffer While read thread doesn't pops elements from MultithreadQueue, write threads adds new elements to activeQueue. When read thread requires new element, algorithm checks, if bufferQueue has elements, pops from bufferQueue, swaps queues else and pops from new buffer (empty bufferQueue becames activeQueue to receive new elements), else returns default and false.


For writers

  • Enqueue({Element]) - add element to queue

For readers

Only reader's thread methods marked by prefix "R_"

  • void R_Swap() - swaps active and buffer queues
  • bool R_DequeueReady(out T nextObj, bool swapAutomatically = true) - nextObj - next element in bufferQueue, swapAutomatically - flag to swap queues (returns element only from bufferQueue if the bufferQueue is empty, swaps queues and returns default and false)
  • bool R_Dequeue(out T nextObj) - deq dequeues next element (default) and returns success status
  • MultithreadQueue<T> R_PopToNewQueue() - returns new MultithreadQueue with all elements and clears current queues
  • Queue<T> R_PopAllToNewQueue() - returns queue with all elements on the call time.
  • IEnumerable<T> R_PopAll() pops all elements from queue with enumerable (can be used in foreach cycle) and dequeue their
  • void R_Clear() clears MultithreadQueue
  • bool R_IsEmpty check if the MultithreadQueue is empty
Experemental reader wait for new elemtns methods
  • Queue<T> R_PopAllToNewQueue_Wait(int timoutMs = -1) - returns all elements on the call time or waits for new elements if empty
  • T R_Dequeue_Wait(int timoutMs = -1) - get next element or wait for a new one. timoutMs = -1 is infinity time to wait
  • bool R_CheckMayHaveNew() - returns true if queue can contain new element, never returns false, if queue isn't empty
  • void Wait(int timoutMs = -1) - wait for new element. timoutMs = -1 is infinity time to wait
  • public WaitHandle NewElementWaiter { get; } - property to get new element WaitHandle

Also MultithreadQueue<T> implements IEnumerator<T> interface and can be used in foreach cycles (without elements dequeue)

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 88 5/16/2021
1.0.0 88 5/12/2021

+ nuget description