final class · System.Threading
ConcurrentQueue<T>
public final class ConcurrentQueue<T>
A queue several threads use at once (a lock around a Queue).
- Kind
- final class
- Namespace
- System.Threading
- Assembly
- System.Core
- Access
- public, final
- Source file
Threading.ant
Type parameters
| Name | Constraints |
|---|---|
T | any type |
Inheritance
- Base classes
-
AnyConcurrentQueue<T>
Constructors
new()
#
Properties
Methods
Enqueue(T item)
#
TryDequeue(T fallback) : T
#
The first item, taken out; fallback when the queue is empty.
Dispose()
#
Frees what it holds (it must not be used after).
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
ConcurrentQueue<T> as Antril, decompiled from its Larva HIR.
// System.Threading.ConcurrentQueue — System.Core (decompiled from Larva HIR)
import System;
into namespace System.Threading
{
/// A queue several threads use at once (a lock around a Queue).
public final class ConcurrentQueue<T>
{
Mutex mutex;
Queue<T> items;
public:
new()
{
mutex = new Mutex();
items = new Queue<T>();
}
Enqueue(T item)
{
mutex.Lock();
items.Enqueue(item);
mutex.Unlock();
}
/// The first item, taken out; `fallback` when the queue is empty.
TryDequeue(T fallback) : T
{
mutex.Lock();
T item = items.Count > 0 ? items.Dequeue() : fallback;
mutex.Unlock();
return item;
}
/// Frees what it holds (it must not be used after).
Dispose()
{
mutex.Dispose();
}
i32 Count
{
get
{
mutex.Lock();
i32 n = items.Count;
mutex.Unlock();
return n;
}
}
bool IsEmpty
{
get => Count == 0;
}
}
}