multithreading - C++ - Producer / Consumer only allow consumption in defined chunks -
there's 2 threads a (producer) , b (consumer).
the data a produces meant read in chunks, hence b shall allowed read once a has produced whole chunk. single piece of data simple struct , chunk length variable. example once b allowed read after 50 pieces of data produced, time might 200.
i've found implementation of producer/consumer queue i'd use: https://github.com/cameron314/readerwriterqueue
my current idea a writes data std::vector , pass std::vector queue. doubt works since queue not know how memory std::vector take , wants allocate memory beforehand.
i hope knows easier solution this.
regardless of produce or consume, need concurrent queue communication between producer(s) , consumer(s). if doing c++ style, you'll end like:
template<typename t, typename alloc> class concurrent_queue; (note libraries give such containers, intel tbb example).
the template parameter t exchange between producers , consumers. asked consume chunks, here t = your_chunk_type. let's chunks variable size: chunk = std::vector<something>. lib you've linked on github, use readerwriterqueue<chunk> queue sharing work.
Comments
Post a Comment