John Bass locking?

Bob Speray bob at luke.UUCP
Sat Oct 12 15:30:08 AEST 1985


In article <245 at 3comvax.UUCP> mikes at 3comvax.UUCP (Mike Shannon) writes:
>	What's the nitty gritty on 'John Bass' locking?  How about some
>history, tradeoffs, etc?

I'm not the best one to talk about this issue.  John Bass, are you out there?

The locking I refer to when using the term "John Bass locking" is a chapter 2 
call provided by the Plexus version of sys3 Unix. I beleive the name
comes from the person who originally championed the cause at Fortune Systems.

Plexus people claim that this same function is defined for unix sys5.2 rel 3
from AT&T.  Plexus unix sys5 version 1.2 has the "locking" call in it.

SYNOPSIS
	locking( fildes, mode, size )  long size;

DESCRIPTION
    Locking allows a specified number of bytes to be accessed only
	by the locking process.  Other proceses that attempt to lock, read,
	or write the locked area must sleep until the area becomes locked.

	Mode is 0 to unlock the area.  Mode is 1 to lock the area with a
	sleep until it is available.  Mode is 2 to lock the area with
	an error return if the area is already locked.

	Deadlock is checked and an error is returned if sleeping on the locked
	error would cause a deadlock.

	Closing fildes automatically releases any locks the process has on
	a file.  (i.e. locks are released at process termination)


In usage, the locking call is preceeded by a file open and an lseek to the
byte offset that is to be locked.  The designated number of bytes from
the current offset are locked.

An entire record image can be reserved for exclusive access, preventing
anyone from even reading it.

The locked bytes do not actually need to exist.  For example,
an empty file can be used as the basis for a protocol between competing 
writing processes.  

Each writing process locks corresponding pseudo "field images" in the 
empty file in order to coordinate updates.  The actual images in the real 
database remain unlocked so that reading processes are not hindered.
Of course, this protocol is not a very good solution for the concurrency 
problem, but it does demonstrate the point of locking non existing bytes.

I think the locking call is a great gain over standard sys3.  Plexus
has done right by providing it.  We use it for more than just "locking".

It has been the best way for us to get semaphores in sys3.
The other technique of opening a file create exclusive as is done by
lpr is just too expensive - several seconds for the open and a file
descriptor consumed for each semaphore.

Having a process's locks cleared by the system on process termination is a real
advantage.  Other models of locking that are implemented at the user level 
have special considerations on error exits, on boots, etc.  That type
activity belongs in the OS.

Robert Speray
Benetics Corp



More information about the Comp.unix mailing list