Import std.concurrent.concurrent_queue
std.concurrent.concurrent_queue
A first-in, first-out queue for any number of threads at once.
ConcurrentQueue<T>: first in, first out, for any number of threads at once, with no limit but
memory and what an Int counts. The values are in a Channel, which is a ring, behind a Mutex,
and a Channel twice the size takes its place once it's full, so Enqueue never waits for room,
and TryDequeue never waits for a value: a Channel is what waits.
std/concurrent/concurrent_queue.fb
Types
ConcurrentQueue
class
Public Shared Class ConcurrentQueue<T: Sendable> Implements Defaultable
A first in, first out queue that threads share, which any of them adds to and takes from.
Examples
Const queue = ConcurrentQueue<Int>()
Parallel For i = 1 To 10
queue.Enqueue(i)
End For
Expect(queue.Count == 10)
Local sum = 0
For value In queue.ToArray()
sum += value
End For
Expect(sum == 55)std/concurrent/concurrent_queue.fb, line 43
-
A new, empty ConcurrentQueue.
-
How many values there are, which other threads may change at any time.
-
Puts
valueat the back. Panics when the ConcurrentQueue has as many values as an Int counts. -
The same as Enqueue.
-
Enqueues each of the
values, in order, all read first. Other threads' may come between them. -
Takes the front value off and gives it, or Null when the ConcurrentQueue is empty.
-
The front value, which stays, or Null when the ConcurrentQueue is empty.
-
The values from the front, the order TryDequeue gives them, in a new array.
-
Removes every value. They go once it holds no lock, so a Destroy that their going runs can use the ConcurrentQueue.
-
A new, empty ConcurrentQueue.
Report an issue with this page or with FutureBlitz on GitHub.