Processing a central data buffer for many processes in C ++

I ran into the following problem and cannot decide how to proceed:

I have a class, Readerreceiving a piece of data every 1 / T seconds (in fact, the data is taken from video frames, 30 frames per second). Pieces should be transferred to several objects Detectorsthat process the pieces and make a decision. However, the number of fragments that each detector must read before making a decision varies, for example. some may need only one piece, about 51.

I mean the presence of a data buffer in which it Readerplaces readable pieces of data, implementing a publication / subscriber to register each Detectorand send it a signal when there are enough frames for it to process in the data buffer. Is this a good approach? Also, what is the best way to manage a buffer and Detectorsread data from it without making your own copies? Common pointers?

Thanks a lot!

FROM

+3
source share
3 answers

I think (also based on your comment on Maciek) you should start by understanding the difference between threads and processes and how they can communicate.

: . , shared_ptr , *. AFAICR, boost:: shared_ptr , , . (). , (o (1)) ( , 51 shared_ptrs ) /.

, , . , ( bcat). (/ ) . , , . (, - , , ? ? , ...) , , , shared_ptrs ( ).

, . , .

.

* - . push (j) pop() , , ( stl:: queue). , ). , stl:: queue boost:: mutex.

+2

/ . , , ( , , ).

, , , () , , - , c.f. -.

+4

, .

boost:: interprocess ( boost.org).

What you are looking for is boost :: interprocess / managed_shared_memory. It will be a little strange at first, but as soon as you get it you will like it.

What you want to do: Create a managed shared memory segment. Select the object that will handle interprocess communications using void_allocator (search for dispensers). Implement synchronization mechanisms (boost :: interprocess: semaphore and boost :: interprocess_mutex, for example). Embed communication from individual processes through managed shared memory.

+2
source

Source: https://habr.com/ru/post/1720499/


All Articles