jeudi 28 janvier 2016

C++ - Producer / Consumer only allow consumption in defined chunks

There's two threads A (Producer) and B (Consumer).

The data A produces is only meant to be read in chunks, hence B shall only be allowed to read once A has produced a whole chunk. A single piece of data is a simple struct and the chunk length is variable. For example once it could be that B is allowed to read after 50 pieces of data are produced, another time it might be 200.

I've found this implementation of a producer/consumer queue that I'd like to use: http://ift.tt/1wsl4Cd

My current idea is that A writes its data into a std::vector and then pass the std::vector into the queue. But I doubt this works since the queue does not know how much memory an std::vector will take and it wants to allocate the memory beforehand.

I hope anybody knows an easier solution for this.

Aucun commentaire:

Enregistrer un commentaire