Multiple machines in the LAN are appending lines to a server file. How do I avoid possible clashes?

By Herb

There are several client machines B … N which access a text file on server A in order to append a single line (these lines are instructions to A to do something, the file itself is a FIFO instruction queue). The file is small, and most of the time completely empty. There are apps on A itself appending lines to this file.

Machines B to N do write only to this file, but it is unforeseeable when, so access violations are likely to occur every so often.

Machine A checks this file every second, removes all currently existing lines line by line (FIFO), while executing said instructions. Of course, there is a high potential for access violations here (as clients happen to currently append to the file), but this is quite negligible, as the intended operation simply can be aborted (because a retry happens anyway each second and timing is not that crucial).

The main problem I have is with the client machines. How do I ensure, that I can still safely append to the file on A, when A is actually manipulating it? Should I just follow A’s strategy and try and try every second, until it succeeds, or is there a special I/O setting for exactly these purposes?

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273