sleeping while at spltty?

Steve Nuchia steve at nuchat.UUCP
Mon Apr 17 15:33:38 AEST 1989


In article <824 at twwells.uucp> bill at twwells.UUCP (T. William Wells) writes:
>	splsave = spltty();
>	while (!carrier_detect || already_opened) {
>		sleep(&line_flags, 29);
>	}
>	splx(splsave);
>
>My understanding of the spl# calls is that they disable interrupts;
>
>So, could someone clue me in on what is really happening?

The missing piece is that the sleep call "does the right thing".
In particular, it remembers the SPL level in effect, suspends
the current process, and reactivates (through part of the
diffuse "scheduler algorithm") some other process, at the
SPL it sent to sleep at.

If you couldn't call sleep from an elevated SPL there would
be unavoidable race conditions in your code, watch:

	x = spltty();
	while ( !flag )
	{
		splx(x);
		sleep(&flag, TTYIN);
		x = spltty();
	}
	splx(x);

If the interrupt occurs after the first spltty it will be serviced
between the inner splx and the sleep call.  The wakup(&flag) in
the interrupt routine is nor prescient, so it has no effect on
the sleep that happens on return from the interrupt.  Now nothing
will wake up your process.  Depending on the priority you've
chosen you may have just created one of the famous unkillable
processes.

-- 
Steve Nuchia	      South Coast Computing Services
uunet!nuchat!steve    POB 890952  Houston, Texas  77289
(713) 964 2462	      Consultation & Systems, Support for PD Software.



More information about the Comp.unix.wizards mailing list