Re: how to write to a file without race condition

From: James (jas_at_spamcop.net)
Date: 07/18/04

  • Next message: James: "Re: how to write to a file without race condition"
    Date: Sun, 18 Jul 2004 11:44:21 +0100
    
    

    On 17 Jul 2004 23:08:30 GMT, Casper H.S. Dik <Casper.Dik@Sun.COM>
    wrote:

    >James <jas@spamcop.net> writes:
    >
    >>No, each of them will atomically seek to the current EOF, append their
    >>data, then the next one will write at the new EOF. They won't
    >>overwrite each other unless they're running over NFS (which introduces
    >>a race condition) or they used lseek with an explicit offset rather
    >>than SEEK_END.
    >
    >Why do you believe that lseek(..., SEEK_END) has this magic
    >property?

    That's what Alex Colvin said earlier in the thread. It *doesn't* have
    this property (which is hardly "magic", since it amounts to setting
    the O_APPEND flag!), but until I checked for myself his explanation
    seemed reasonable, particularly in the absence of any challenge until
    yours. (James Antill *agreed* with it, then changed his mind
    mid-post...)

    > lseek sets the file pointer and the only thing "SEEK_END"
    >does is to set the file pointer relative to the current end.

    Correct. As I said earlier, to achieve the result described you need
    to set O_APPEND rather than using lseek().

    James.


  • Next message: James: "Re: how to write to a file without race condition"

    Relevant Pages

    • Re: how to write to a file without race condition
      ... experimentation on Linux, however, this isn't the case. ... then the next one will write at the new EOF. ... > While I don't currently have access to try it myself on a Solaris ... the time lseek was called. ...
      (comp.unix.programmer)
    • Re: Adding to binary files
      ... Is it possible in ProDOS to either combine file segments on ... you should be able to append to a file by doing OPEN ... SET_EOF past the current EOF and do a SET_MARK between the old EOF ... jmatthews at wright dot edu ...
      (comp.sys.apple2.programmer)
    • Re: fscanf
      ... It just says append is a possible mode with a+ also which is append-read mode. ... The value EOF is returned if the end of input is reached before either the first ... means checking the values returned by things like fscanf. ... Wouldn't you be curious, whether fscanf converted zero, one, or two items? ...
      (comp.lang.c)
    • Re: how to write to a file without race condition
      ... >> On at least some UNIX systems (Solaris), ... >lseek was called. ... No, each of them will atomically seek to the current EOF, append their ...
      (comp.unix.programmer)
    • Simple RMS question
      ... I want to open a sequential file using RMS, append a single line and close it. ... When calling SYS$PUT I get the error %RMS-F-NEF which is not positioned to EOF on $PUT if the file is nonblank. ...
      (comp.os.vms)