Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ design pattern for input multiplexing?

I have to read and process data synchronously in my program from several sources, like the following:

main
...
while(true)  {
dataSample1 = readInput1...
processData(dataSample1) 
....
dataSample2 = readInput2...
processData(dataSample2) 
}

Each readInput is implemented in separate component to deal with different nature of inputs (e.g. sockets, usb port, etc. ), but the format for data samples is the same. The problem is that both readInput and processData are blocking, so I have to come up with solution to multiplex reading of inputs for "processData". Does this problem correspond to "reactor" or "proactor" pattern? Are there frameworks to help with implementation without moving each "readInput" into separate thread?
Thanks...

like image 824
user270398 Avatar asked Jul 17 '26 04:07

user270398


1 Answers

Are you able to rewrite/reconfigure the various readInput functions to become non-blocking? If not, separate threads (maybe even separate processes) are the only way to have them running in parallel. If yes, then a reactor pattern can help you trigger the right processing when each input arrives.

like image 132
Ben Voigt Avatar answered Jul 18 '26 19:07

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!