Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!cs.utexas.edu!yale!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.unix.wizards Subject: Re: The 4.3 BSD awrite() solution Summary: it works, and here are the tests to prove it Message-ID: <6068:00:23:14@stealth.acf.nyu.edu> Date: 9 Feb 90 00:23:15 GMT References: <1055.18:35:28@stealth.acf.nyu.edu> <131445@sun.Eng.Sun.COM> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 81 Larry, why don't you at least test the code before asserting that it doesn't work? I've now run my async library through a rather thorough series of tests. It works perfectly. aread() and awrite() don't block. Your theoretical error is the assertion that a system call can't be interrupted by a signal (except in an obscure situation, where you consider the behavior to be in error). But a blocked system call can be interrupted. That's why siginterrupt() exists. Try compiling this code and feeding it into various situations. Try it with the interrupt flag changed from 1 to 0. Try it with write() instead of awrite(). Try similar tests with reading. You'll become a believer too. #include #include #include "async.h" main() { char buf[100000]; siginterrupt(SIGALRM,1); /* this should be in the async library, I guess */ fprintf(stderr,"%d\n",awrite(1,buf,sizeof(buf))); } Here are a few tests I tried on a Sun with the above program: kramden% ./astest > /dev/null 100000 kramden% ./astest | cat | wc 4096 0 0 4096 kramden% ./astest | sleep 2 4096 kramden% (sleep 1;./astest) | cat|wc 4096 0 0 4096 kramden% !! ( sleep 1 ; ./astest ) | cat | wc 8192 0 0 8192 kramden% !! ( sleep 1 ; ./astest ) | cat | wc 8192 0 0 8192 kramden% !! ( sleep 1 ; ./astest ) | cat | wc 8192 0 0 8192 Notice the effects of various caching mechanisms: after the first time, cat starts much more quickly. Obviously kramden's pipes hold 4096 bytes. kramden% ./astest | cat > ascat 4096 kramden% ls -l ascat -rw------- 1 brnstnd 4096 Feb 8 18:06 ascat kramden% (cat ascat; ./astest; sleep 10; ./astest) | (sleep 5; cat) | wc -1 8192 0 0 12288 kramden% (cat /etc/termcap;./astest) | (sleep 2; cat) | wc 1730 2724 10772 135168 kramden% wc /etc/termcap 2724 10772 133438 /etc/termcap If those last two lines don't convince you I don't know what will. (135168 is 33 times 4096.) One comment on your comments: > (this is what almost every Unix system does anyway unless > you have opened the file with O_SYNC, so this is a moot point, but...). What about pipes, ttys, and sockets? None of this is moot. My multitee program works beautifully. More evidence for the superiority of BSD over System V... ---Dan