Are terminal writes atomic?

William G. Bunton wgb at tntdev.tnt.COM
Mon Oct 9 00:20:28 AEST 1989


On 7 Oct 89 19:17:44 GMT,
mark at promark.UUCP (Mark J. DeFilippis) said:
Mark> Summary: I should have qualifed this...

Mark> In article <19972 at mimsy.UUCP>, chris at mimsy.UUCP (Chris Torek) writes:
> In article <186 at promark.UUCP> mark at promark.UUCP (Mark J. DeFilippis) writes:
> >How about we take this further.  The answer to this question is an
> >undocumented feature of write() under Unix.  Several Authors note this
> 
> Of course, it might be undocumented because it is false.
> 
> On Berkeley systems (4BSD, at least), writes to character devices are

Mark> Indeed I should have qualified my statement, however almost
Mark> everyone is familiar with Rochkind's _Advanced Unix Programming_
Mark> book, and they are aware it is a SYSTEM V book, not a 4BSD Unix
Mark> book.  Under System V, it is a known undocumented item.  By
Mark> undocumented, I mean it was left out of the documentation and
Mark> under ALL true Unix System V systems, atomic writes at the
Mark> system call level are guaranteed. Yes, 4BSD is different and
Mark> causes much grief with which I am familiar with.  That is why I
Mark> am glad that most porting I do is from 4.XBSD to System V, and
Mark> not the other way around!  I assume you don't get out from under
Mark> 4.XBSD that often huh?

But Mark, it isn't true under System V, either.  Bach says (Design of
the UNIX Operating System) section 10.3.2, page 33:

"Output data could also be garbled at a terminal because a writing
process may sleep in the middle of a *write* system call while waiting
for previous output data to drain from the system.  The kernel could
schedule other processes that *write* the terminal before the original
process is rescheduled.  Because of this case, the kernel does *not*
guarantee that the contents of the data buffer to be output by a
*write* system call appear contiguously on the terminal."

Note the emphasis is his, not mine.  I think this is why atomic
terminal writes are not documented for System V: because they are not
guaranteed atomic.

Bill
-- 
William G. Bunton                                        wgb at tntdev.tnt.com
Tools & Techniques, Inc. Austin, TX        {cs.utexas.edu,uunet}!tntdev!wgb



More information about the Comp.unix.questions mailing list