[comp.bugs.sys5] Sleep

bill@twwells.uucp (T. William Wells) (05/23/89)

In article <1232@netcom.UUCP> chris@netcom.UUCP (Chris Lakewood) writes:
: In article <913@twwells.uucp] bill@twwells.UUCP (T. William Wells) writes:
: ]And then consider sleep(). I know of one system where sleep was
: ]implemented as a system call (and documented in section 2) because
: ]the standard version of sleep would hang occasionally. Consider:
: ]
: ]     alarm(n);
: ]     pause();
: ]
: ](the guts of sleep) and what happens if the process doesn't run for n
: ]seconds. Have you ever had tail hang on a heavily loaded system? (I
: ]have.) Guess why.
: ]---
: ]Bill                            { uunet | novavax } !twwells!bill
:
: Don't leave us in suspense...  What happens if the process doesn't run for
: n seconds?  Actually, the process won't run for at least n seconds unless
: it receives some signal.  The pause causes the process to block until a
: signal is received.

Here's some suspense:

	alarm(n);
	<other processes grab the system for at least n seconds>
	<the alarm signal happens>
	<the sleep alarm handler does nothing>
	pause();
	<which can never return, since the alarm happened before the pause>

The problem is that, in order for alarm to work reliably with pause,
the alarm must be prevented from occuring before the pause executes.
Since there wasn't an atomic method of doing this, sleep could hang.

Another way to fix this would have been to have the signal handler do
a long jump, but I suspect that this would have caused problems of
its own.

(Sorry for the delay in answering. And also if someone has already
answered this: my newsfeed backed up a week and they "fixed" the
problem by tossing a week of news! Argh.)

---
Bill                            { uunet | novavax } !twwells!bill