Question on how to implement exclusive scheduling

Geoff Kuenning geoff at desint.UUCP
Sun Oct 14 06:26:58 AEST 1984


I think that a system call to prevent process switching is probably not the
right way to go.  You will run into a number of problems, the biggest of
which is that you are violating a fundamental assumption of the design of the
operating system (i.e., that it can switch processes when it wants to).  It
is impossible (at least for me) to predict where Unix would object, but I
sure wouldn't be surprised if your first attempt failed miserably and
mysteriously.

What is wrong with the famous "locking" (or "lockf") system call, which
locks access to a particular area of disk?  I even think it's on 4.2bsd.  If
not, here's an outline of an implementation:

	struct locktab {you-figure-this-part-out} locktab[NLOCK];

	locking () {
		<convert user's byte range into a device and absolute disk
		    byte range(s)>
		while (1) {
			<search locktab to see if that range is locked>
			if (locked)
				sleep (&locktab_entry);
			else
				break;
		}
		<make new locktab entry to mark byte  range as locked>
	}

	unlock () {
		<remove locktab entry>
		wakeup (&locktab_entry);
	}

Since this is implemented in the kernel, it is clean and simple.  It also has
the advantage that it does not lock out the whole world when there are
probably only a few processes that are likely to be a problem (do you really
want to shut off uucp and the print spooler while you access those bytes?).
And a runaway process won't grab the CPU so it can't be killed.

Fleshing this code out is simple if you are a kernel guru.  If you are not,
you really don't have any business mucking with swtch() anyway.
-- 
	Geoff Kuenning
	First Systems Corporation
	...!ihnp4!trwrb!desint!geoff



More information about the Comp.unix.wizards mailing list