Template Class ThreadsafeBatchingPool

Class Documentation

template<class BatchingPoolType>
class ThreadsafeBatchingPool

The following mechanism operates in a multithreaded async-workflow guarding access to the pushes to the structure keeping sentences bucketed by length and sorted by priority.

This is a wrap of a producer-consumer queue implemented as a monitor, where there is a mutex guarding the underlying data structure (BatchingPoolType) and (worker/consumer) threads waiting on a condition variable and the queuing thread producing and notifying waiting threads (consumers) through the same condition variable.

Originally written by for a single model (where items are produce: Request, consume: Batch), converted to also work for multiple models where items are produce: (TranslationModel, Request), consume: (TranlsationModel, Batch). This is accomplished by template parameter packs.

Requires BatchingPoolType to implement the following:

  • produce: size_t enqueueRequest(...) (returns number elements produced)

  • consume: size_t generateBatch(...) (returns number of elements available to be consumed)

Public Functions

template<class ...Args>
ThreadsafeBatchingPool(Args&&... args)
~ThreadsafeBatchingPool()
template<class ...Args>
void enqueueRequest(Args&&... args)
template<class ...Args>
size_t generateBatch(Args&&... args)
void clear()
void shutdown()