Next Previous Up Top Contents Index

11 Multiprocessing

11.3 Locks

Locks can be used to control access to shared data by several processes.

A lock has the following components: name (a string), lock (t ornil, that is, whether the lock is set or not), owner (a process, ornil) and count (an integer showing the number of times the lock has been set).

The two main symbols used in locking are the functionmake-lock, to create a lock, and the macrowith-lock, to execute a body of code while holding the specified lock.

mp:make-lock

Function

mp:make-lock &key important-p &allow-other-keys

Creates a lock object. Ifimportant-p ist the lock is added to the list held in the global variablemp:*important-locks*. The functionmp:free-important-locks frees all important locks associated with a given process (or all the important locks if called onnil). Other keywords should be names of the lock components.
mp:process-lock

Function

mp:process-lock lock &optional whostate timeout

Blocks the current process until the lock is claimed ortimeout elapses if it has been specified. Returnst if lock was claimed,nil otherwise.
mp:process-unlock

Function

mp:process-unlock lock &optional errorp

Releases the lock. If errorp is non-nil it signals an error if the current process does not own the lock. The default value of errorp ist.
mp:with-lock

Macro

mp:with-lock ((lock &rest lock-args) &body body

Executes the body with lock held. Arguments to pass on tomp:process-lock are specified using lock-args.
The following accessors are available for locks:lock-owner,lock-count,lock-name andlock-lock.

LispWorks User Guide - 14 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker