Thread safety for adding a single file from several processes?

Say I have X processes opening a Y file to add. Each process writes only one line (with \ n) at a time (indeed log entries).

Is each line guaranteed that it does not alternate incorrectly in the Y file?

UPDATE: local file system.

+4
source share
1 answer

The question depends on what type of recording is taking place. If you use standard buffered I / O, which is usually the default by default for a program, then the buffer will be cleared only after several lines are written, and when they are flushed, this will not necessarily be an integer number of lines. If you use write (2) or changed the default stdio buffering to be string or unbuffered, then it will alternate correctly if the lines are of reasonable size (of course, if the lines are less than 512 bytes).

0
source

All Articles