Charles.Forsyth20060303-partialeea662d19 years agoHistory
110 lines · 2.8 KB · Text
RawDownload
.TH LOCK 10.2.SH NAMElock, canlock, ilock, iunlock, unlock \- spin locks.SH SYNOPSIS.ta \w'\fLvoid 'u.Bvoid    lock(Lock *l).PP.Bint     canlock(Lock *l).PP.Bvoid    unlock(Lock *l).PP.Bvoid    ilock(Lock *l).PP.Bvoid    iunlock(Lock *l).SH DESCRIPTIONThese primitives control access to sharedresources using spin locks.They in turn are used to build higher-level synchronisation mechanismssuch as those described in.IR sleep (10.2),.IR qlock (10.2)and.IR qio (10.2).They should be used only to protect short critical sectionsthat update shared data structures..PP.I Lockloops repeatedly attempting acquire the spin lock.I luntil it succeeds..I Lockshould not be used to lock a structure shared with an interrupt handlerunless interrupts are disabled by.IR splhi (10.2)before attempting the lock;it is better to use.IR ilock ,below..PP.I Canlockis non-blocking.Only one attempt is made for the lock.It returns non-zero if the lock was successfully acquired; 0 otherwise..PP.I Unlockreleases the lock.IR l .A lock must be unlocked only by the locking process..PPWhen called by a process, the functions above temporarily boost its priorityto the highest priority,.BR PriLock ;its original priority is restored at the end of the critical section by.IR unlock .On a uniprocessor, if.I lis unavailable,.I lockcan reschedule unless interrupts are disabled before entering.I lockor there is no current process (eg, when executing the scheduler)..PP.I Ilockdisables interrupts before attempting to acquire the lock.It should be used to lock a resource shared between a process and an interrupt handler.On a uniprocessor, disabling interrupts is sufficient to exclude an interrupt handlerfrom the critical section,and on a multiprocessor the spin lock excludes an interrupt handler running on another processor..I Ilocknever reschedules the caller, nor must a caller allow itself to be rescheduled(eg, by calling.IR sleep (10.2))before releasing the lock..PP.I Iunlockreleases a lock previously got by.IR ilock ..SH DIAGNOSTICSThe lock functionsguard against the possibility of never acquiring the lock by capping the number of lock attempts.If the limit is reached, a message ofthe following form is written on the console:.IP.EXlock loop on \fIlock-address\fP key \fIkey-value\fP pc \fIcaller-pc\fP held by pc \fIlock-pc\fP.EE.PPMost lock loops represent deadlocks caused by failing to unlock a resource,attempting to lock (eg, by recursive call) a resource already held by the process,inconsistent locking and unlocking of nested resources, using a spin-lockto guard code that reschedules, using.I locknot.I ilockto interlock with an interrupt routine, and similar blunders..SH SOURCE.B /os/port/taslock.c.br.B /os/*/l.s.br.B /emu/port/lock.c.br.B /emu/*/os.c.SH SEE ALSO.IR qlock (10.2)