|
CNum 0.2.1
CPU-optimized ML library for C++
|
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. | |
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
| CNum::DataStructs::ConcurrentQueue< T >::ConcurrentQueue | ( | ) |
Default constructor.
|
default |
| bool CNum::DataStructs::ConcurrentQueue< T >::dequeue | ( | T & | val | ) |
dequeue a value
| val | Reference to the variable to store the popped value in |
| bool CNum::DataStructs::ConcurrentQueue< T >::empty | ( | ) |
Check if the queue is empty.
| void CNum::DataStructs::ConcurrentQueue< T >::enqueue | ( | T | val | ) |
Enqueue a element.
| val | The element |
| 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
| bool CNum::DataStructs::ConcurrentQueue< T >::stop_is_set | ( | ) |
Check stop flag for thread pool.