in reply to Re^2: Append to text file not working
in thread Append to text file not working

As long as your writes are below one page of data (2k is safe), then with most filesystems your writes are atomic and no locking synchronization is needed. That looks like it is true in this case.

If locking synchronization is needed, then flock is not necessarily the right place to start looking because (depending on the filesystem) it can be highly unreliable.

Replies are listed 'Best First'.
Re^4: Append to text file not working
by cmeyer (Pilgrim) on Feb 22, 2008 at 02:19 UTC

    I'm sure that you meant to specify that your writes are atomic, when writing to files that were opened for append.

    I prefer that posts in public forums err towards the pedantic side. :)

    -Colin.

      If you want to get pedantic, the actual writes to the filesystem (in memory at least) are atomic in either case. However if you have not set append (or, reading some C documentation, if you're unlucky enough to be using NTFS) it is the case that one process could write to a location in the file that another process has already overwritten, thereby overwriting what the other process wrote.

      So technically the writes are atomic, but the end result could still disappoint. :-)