SimpleMultithreadQueue 1.0.1

.NET Standard 2.0
dotnet add package SimpleMultithreadQueue --version 1.0.1
NuGet\Install-Package SimpleMultithreadQueue -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#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

SimpleMultithreadQueue

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.

Methods

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)

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .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 290 5/16/2021
1.0.0 213 5/12/2021

+ nuget description