There are two programs in c++ , one of which in the loop constantly writes data to .bin , and the other reads it all the time. Sometimes there are data that do not correspond to reality, apparently due to simultaneous access to the file.

As I understand it, it is necessary to use one of the interprocess communication methods to eliminate such things. Which of these methods can you recommend as the "easiest and most reliable"?

And, if possible, please give a link to an example.

  • 2
    Considering that you are working with a file, it would be logical to use file locking, i.e. flock() - Mike
  • one
    Mike wrote correctly. Before each reading and writing you 1) lock the file, 2) work with the file 3) remove the lock from the file Thus, the file acts as an interprocessor communication tool - Alexus
  • zeroMQ zeromq.org for example - Vyacheslav Danshin
  • one
    @VyacheslavDanshin, zmq instead of the common flock() ? - PinkTux
  • 2
    @AlxZahar linux.die.net/man/2/flock If the LOCK_NB flag is passed, then it will be non-blocking and return an error, if it is not there, it will stop before receiving it - Mike

0