TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Public Types | Public Member Functions | List of all members
common::BufferedProducer< T > Class Template Reference

A simple producer class. More...

#include <parallel.h>

Public Types

using type = T
 

Public Member Functions

 BufferedProducer (uint8_t nthreads, size_t maxQueueSize, Function &&fn)
 
 ~BufferedProducer ()
 Stops the producers, discarding any items in the queue. More...
 
std::optional< T > get ()
 
void run (Function fn)
 

Detailed Description

template<typename T>
class common::BufferedProducer< T >

A simple producer class.

You specify a function that will generate data for you somehow, ending when it returns an optional without a value, and this producer will multithread it for you automatically. The function should be thread-safe, and data is not guaranteed to arrive in the same order it was generated in, unless you do it yourself. If you want to stop the consumer threads, destruct the object. If you try destructing the object while get() is still being called, it will result in a runtime error.

Member Typedef Documentation

template<typename T >
using common::BufferedProducer< T >::type = T

Constructor & Destructor Documentation

template<typename T >
common::BufferedProducer< T >::BufferedProducer ( uint8_t  nthreads,
size_t  maxQueueSize,
Function &&  fn 
)
template<typename T >
common::BufferedProducer< T >::~BufferedProducer ( )

Stops the producers, discarding any items in the queue.

Member Function Documentation

template<typename T >
std::optional< T > common::BufferedProducer< T >::get ( )
template<typename T >
void common::BufferedProducer< T >::run ( Function  fn)

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