Libthreadar 1.6.0
|
the class ratelier_gather's purpose it gather works from several worker threads More...
#include <ratelier_gather.hpp>
Public Member Functions | |
ratelier_gather (unsigned int size, signed int flag=0) | |
ratelier_gather (const ratelier_gather &ref)=delete | |
ratelier_gather (ratelier_gather &&ref)=default | |
ratelier_gather & | operator= (const ratelier_gather &ref)=delete |
ratelier_gather & | operator= (ratelier_gather &&ref) noexcept=default |
void | worker_push_one (unsigned int slot, std::unique_ptr< T > &one, signed int flag=0) |
provides to a worker thread a mean to given data with its associated index to the gathering thread More... | |
void | gather (std::deque< std::unique_ptr< T > > &ones, std::deque< signed int > &flag) |
obtain the lowest continuous filled slots from the ratelier_gather and free them More... | |
void | reset () |
reset the object in its prestine state More... | |
the class ratelier_gather's purpose it gather works from several worker threads
Each worker has to send its job result to the ratelier_gather with an index number. This index is used to provide the jobs in sequence to the gathering thread and starts to zero. If a index is missing no data is delivered to the gathering thread until a worker thread provides it. The gathering thread is thus garantied that whatever the execution order of workers their resulting job is provided in sequence to the gathering thread.
The original design for this class is to work in conjunction with a ratelier_scatter when a sequence of data has to be processed by many workers, but the resulting of the processed data should also be ordered following the original data order whatever the speed or task complexity each worker performed or addressed compared to the others.
+--------------------+ | scattering thread | +--------------------+ | | V (ratelier_scatter) / | \ / | \ +-------+ +-------+ +-------+ |worker1| |worker2| |worker3| +-------+ +-------+ +-------+ \ | / \ | / V V V (ratelier_gather) | | V +--------------------+ | gathering thread | +--------------------+
The number of slots should be greater than the number of workers that fill the ratelier with data to avoid having working pending for a slot. Workers put objects each at a given slot and a non-worker thread (the gathering thread) fetches those objects, which are provided in order, this releases the corresponding slots of the ratelier_gather object for workers to drop next results in it.
Definition at line 99 of file ratelier_gather.hpp.
libthreadar::ratelier_gather< T >::ratelier_gather | ( | unsigned int | size, |
signed int | flag = 0 |
||
) |
Definition at line 156 of file ratelier_gather.hpp.
void libthreadar::ratelier_gather< T >::gather | ( | std::deque< std::unique_ptr< T > > & | ones, |
std::deque< signed int > & | flag | ||
) |
obtain the lowest continuous filled slots from the ratelier_gather and free them
[out] | ones | is a list of continuously indexed objects which immediately follows the list provided by a previous call to gather(). |
[out] | flag | is the purpose free signal transmitted by the workers and associated to each object |
Definition at line 216 of file ratelier_gather.hpp.
References THREADAR_BUG.
void libthreadar::ratelier_gather< T >::reset |
reset the object in its prestine state
this restarts the index to zero. The next index that a worker should give for any data be provided to the gathering thread should be zero.
Definition at line 287 of file ratelier_gather.hpp.
void libthreadar::ratelier_gather< T >::worker_push_one | ( | unsigned int | slot, |
std::unique_ptr< T > & | one, | ||
signed int | flag = 0 |
||
) |
provides to a worker thread a mean to given data with its associated index to the gathering thread
[in] | slot | is the slot number associated to the provided object "one" |
[in] | one | is the object to push to the gathering thread |
[in] | flag | is a purpose free signal to send to the gathering thread as associated to this object. |
Definition at line 166 of file ratelier_gather.hpp.
References THREADAR_BUG.