5.2 Issues in multitasking

5.2.5 Locks

When two processes need to modify the same data, you must make certain that they do not modify the data simultaneously. You can do this by creating a lock to ensure that no more than one process can modify a data structure at a time. A lock is an extra memory location in a data structure that you can check to determine whether a data structure is in use. If the value of a lock isnil, no process is using the data structure; otherwise, the value should be a process that is currently using the data structure.

Any process that wants to modify the data structure must acquire a lock; that is, it must wait until the value stored in the lock location isnil and then set the value of the location to itself. If the lock location is held by another process, the process must wait until the location becomesnil. Note that locks only work if all processes that modify a data structure use them. The lock by itself guarantees nothing.

The Multitasking Facility provides three macros for acquiring and releasing locks:


The macrowith-process-lock temporarily secures a lock while a series of forms are executed; it then releases the lock. The macros process-lock andprocess-unlock provide finer control over locks.

Note: You cannot run the Compiler if another process is using it. If you attempt to do so, your process will wait until the first process is finished using the Compiler. See the reference page for with-process-lock for a description of the behavior of locked processes. - Avoiding deadlocks - A locking example

The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker