> Date: Fri, 31 May 2013 16:58:21 +0200
> Cc: psm...@gnu.org, stefano.lattar...@gmail.com, bug-make@gnu.org
> From: Frank Heckenbach <f.heckenb...@fh-soft.de>
> 
> > > void write (int fd, void *data, size_t size)
> > > {
> > >   if (getflags (fd) & O_APPEND)
> > >     {
> > >       lock_mutex (get_mutex (fd));
> > >       off_t pos = get_size (fd);
> > >       do_write (fd, pos, data, size);
> > >       set_pos (fd, pos + size);
> > >       unlock_mutex (get_mutex (fd));
> > >     }
> > >   else
> > >     {
> > >       // no mutex here!
> > >       off_t pos = get_pos (fd);
> > >       do_write (fd, pos, data, size);
> > >       set_pos (fd, pos + size);
> > >     }
> > > }
> > 
> > If the 'else' clause uses a single file pointer system-wise, there's
> > no overwriting because the pointer is not moved between writes.
> 
> I still can't follow you. Just imagine this function is run by two
> different processes simultaneously with the same FD without
> O_APPEND. Both fetch the current position (get_pos) and get the same
> value. Then both write (do_write) at this same position, overwriting
> each other. Finally, both update the file pointer (set_pos), but
> again, only the 2nd one becomes effective.

There's no reason for them to call get_pos.  do_write moves the
pointer as a side effect.

_______________________________________________
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make

Reply via email to