--- Paul Herring wrote:
> 
> I wrote:
> >  I was thinking about:
> >
> >  Is the sh operator >> to redirect and append a single fwrite to stdout 
> > atomic or not?
> 
> Nope. Not in the conventional programming sense of the word anyway.
> 
> >  Can you prove your answer to the question above?
> 
> Imagine two threads calling sh and using the >> operator.
> 
> First thread gets preempted after opening file, but before writing
> (everything) to it.
> Second thread executes and manages to open, write and close the file.
> First thread swaps back in and completes.
> 
> flock() may, or may not be involved here, but there's still a window
> of opportunity whereby thread 2 can come in before thread 1 has
> completed.

  If fwrite (ptr, size, 1, f) is atomic and
  the sh operator >> use the system call dup(int) then
  the sh operator >> is atomic.

  Am I wrong?


Reply via email to