CNum 0.2.1
CPU-optimized ML library for C++
Loading...
Searching...
No Matches
CNum::DataStructs::ConcurrentQueue< T > Class Template Reference

Coarse-grained locking concurrent queue. More...

#include <ConcurrentQueue.h>

Public Member Functions

 ConcurrentQueue ()
 Default constructor.
 ~ConcurrentQueue ()=default
void enqueue (T val)
 Enqueue a element.
bool dequeue (T &val)
 dequeue a value
void set_stop ()
 Set stop flag for thread pool.
bool empty ()
 Check if the queue is empty.
bool stop_is_set ()
 Check stop flag for thread pool.

Detailed Description

template<typename T>
class CNum::DataStructs::ConcurrentQueue< T >

Coarse-grained locking concurrent queue.

This queue was designed to be used for the thread pool. Perf tests confirmed the course-grained locking approach had perf benefits under load compared to a lock-free approach. This is likely due to the way the pool is used in the CNum ML models which is submitting many instances of smaller tasks. If you need a thread pool with a lock free queue this queue and the ThreadPool class can easily be swapped with the lock-free version on my GitHub

Constructor & Destructor Documentation

◆ ConcurrentQueue()

template<typename T>
CNum::DataStructs::ConcurrentQueue< T >::ConcurrentQueue ( )

Default constructor.

◆ ~ConcurrentQueue()

template<typename T>
CNum::DataStructs::ConcurrentQueue< T >::~ConcurrentQueue ( )
default

Member Function Documentation

◆ dequeue()

template<typename T>
bool CNum::DataStructs::ConcurrentQueue< T >::dequeue ( T & val)

dequeue a value

Parameters
valReference to the variable to store the popped value in
Returns
Whether or not the operation was successful

◆ empty()

template<typename T>
bool CNum::DataStructs::ConcurrentQueue< T >::empty ( )

Check if the queue is empty.

Returns
Whether or not the queue is empty

◆ enqueue()

template<typename T>
void CNum::DataStructs::ConcurrentQueue< T >::enqueue ( T val)

Enqueue a element.

Parameters
valThe element

◆ set_stop()

template<typename T>
void CNum::DataStructs::ConcurrentQueue< T >::set_stop ( )

Set stop flag for thread pool.

This is used to set the stop flag which tells the thread pool not to enqueue any more tasks

◆ stop_is_set()

template<typename T>
bool CNum::DataStructs::ConcurrentQueue< T >::stop_is_set ( )

Check stop flag for thread pool.

Returns
Whether or not the stop flag is set

The documentation for this class was generated from the following file: