template<typename T>
Threading::UnboundedMPMCQueue class

Allows to add tasks and blocking wait for element appearance for multiple writers (producers) and multiple readers (consumers).

Template parameters
T The type of items stored in the queue

User must guarantee no adding in the closed queue, else runtime error exception will be thrown. class UnboundedMPMCQueue A thread-safe unbounded multiple producer multiple consumer (MPMC) queue

Constructors, destructors, conversion operators

UnboundedMPMCQueue() defaulted
Create open queue, which will be ready to accept items.
UnboundedMPMCQueue(const UnboundedMPMCQueue& other) deleted
UnboundedMPMCQueue(UnboundedMPMCQueue&& other) deleted

Public functions

auto operator=(const UnboundedMPMCQueue& other) -> UnboundedMPMCQueue& deleted
auto operator=(const UnboundedMPMCQueue&& other) -> UnboundedMPMCQueue& deleted
void add(T item)
Add task.
void close()
Close queue. All waiting threads will receive nullopt.
auto take() -> std::optional<T>
Block current thread until no item will appearance in the queue or queue will be closed.

Function documentation

template<typename T>
void Threading::UnboundedMPMCQueue<T>::add(T item)

Add task.

Parameters
item the item to be added to the queue

add designed to add an item to the queue std::runtime_error} Thrown when adding to a closed queue.

template<typename T>
void Threading::UnboundedMPMCQueue<T>::close()

Close queue. All waiting threads will receive nullopt.

close it is used to close the queue