Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site sdccsu3.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!sdcrdcf!sdcsvax!sdccsu3!muller From: muller@sdccsu3.UUCP (Keith Muller) Newsgroups: net.news.b,net.bugs.4bsd Subject: Re: Re: alarm() bug in 4.2 Message-ID: <2050@sdccsu3.UUCP> Date: Wed, 11-Jul-84 03:46:43 EDT Article-I.D.: sdccsu3.2050 Posted: Wed Jul 11 03:46:43 1984 Date-Received: Fri, 13-Jul-84 03:39:52 EDT References: <282@voder.UUCP> Organization: U.C. San Diego, Computer Center Lines: 39 > Fortunately, there is an easy workaround; change the previous code > to read: > > for (...) { > oldmask = sigblock(1< ... > sigblock(oldmask); > } I should have looked closer as there is two bugs: (SIGALRM and the second sigblock should be a sigsetmask) for (...) { oldmask = sigblock(1 << (SIGALRM - 1)); .... (void)sigsetmask(oldmask); } Sigblock and sigsetmask together provide a nice way to encapsulate a critical section to protect them from the delivery of asynchronous signals. Along the same grain, sigpause provides a neat way to set a signal mask in an *atomic* manner: oldmask = sigblock(1 << (SIGALRM - 1)); (void)setitimer(.....); sigpause(oldmask); The above code is the only *sure* way to use sigpause with SIGALRM. As you must block against delivery of the SIGALRM between the setitimer() call and the sigpause(). If you don't the program will intermittantly hang forever at the sigpause() (as the SIGALRM *can* be delivered *between* the calls to setitime() and sigpause()). Note that sigpause will restore the signal mask to oldmask after the arrival of the SIGALRM. Keith Muller UCSD Computer Center