Are terminal writes atomic?

Mark J. DeFilippis mark at promark.UUCP
Mon Oct 9 06:31:11 AEST 1989


In article <411 at hitech.ht.oz>, clyde at hitech.ht.oz (Clyde Smith-Stubbs) writes:
> From article <186 at promark.UUCP>, by mark at promark.UUCP (Mark J. DeFilippis):
> > In article <1118 at cs.yale.edu>, spolsky-joel at CS.YALE.EDU (Joel Spolsky) writes:
> >> I think this is safe. A while ago I wrote a little program that runs
> > 
> > How about we take this further.  The answer to this question is an
> > undocumented feature of write() under Unix.  Several Authors note
> > that write() is atomic under Unix and that it is undocumented.
> 
> Rubbish! Writes to terminals under Unix are not, and have never been,
> in any way atomic. In many cases they will be atomic, but there
> is nothing in the structure of the system to guarantee this. It is easy
> [program followed]

Sorry, Under my Unix system V, and my Xenix system as well as
SCO UNIX system V, your program yeilds atomic writes.  However,
this is a coeincidence.  Someone else provided a program 3 articles
after yours which woke me up.
Plus my boss said to me, "Mark, where is your mind? Remember that
application you wrote 3 months ago and the semaphores you had to use to
control simulatneous access by multiple writes?"

I went back to the Rochkind book I mentioned, which I should have done in
the first place, to see where my neural net got it's cross circuit.
He states:

"It is presumably a goal of the /usr/group standards effort to document
important properties like the atomicity of creat, open, and write, But their
proposed standard does not do so.  If this omission is deliberate - that is,
a conforming implimentation does _not_ have to ensure that these systems
calls are atomic, then the standard is seriously defective."

This is a footnote in the book when discussing "The Unix manual fails to
state that writes to files opened with O_APPEND are atomic." However vendors
are only bound by the manual for their implimentation.  "Whats worse, even
a system that doesn't force open and write to be atomic will still act
that way 99 percent of the time, making the bug maddeningly elusive."

A totally different story. Sorry about the confusion, and thanks to those
whose minds were on guard for setting me straight.  I should have known
this stuff anyway, since I have had to impliment semaphores for exactly this
reason in the past.  Sometimes the mind wanders, thats one of the reasons
why we have auto accidents...

Again, my apologies 
-- 
Adelphi University, Garden City, NY 11530                   (516) 663-1170
Department of Mathematics and Computer Science
                                 markd at adelphi.UUCP  or  mark at promark.UUCP
                      UUCP:      ...philabs!sbcs!bnlux0!adelphi!markd



More information about the Comp.unix.questions mailing list