Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (2) — Plan9 3rd Edition (Vita Nuova)

Media Vault

Software Library

Restoration Projects

Artifacts Sought

LOCK(2)

NAME

lock − thread locking. 

SYNOPSIS

include "lock.m";
lock := load Lock Lock->PATH;
Semaphore: adt {
obtain: fn(s: self ref Semaphore);
release: fn(s: self ref Semaphore);
new: fn(): ref Semaphore;
};
init: fn();

DESCRIPTION

­Lock provides semaphore-based mutual exclusion.  ­Init must be called before creating any locks. 

­Semaphore.new()
Creates and returns a reference to a new ­Semaphore (lock). 

s.obtain()
Obtains exclusive access to the lock s. It will block until it can do so.

s.release()
Releases access to the lock ­s and allows processes waiting on it to proceed. 

EXCEPTIONS

If lock allocation fails, a “lock alloc” exception is raised. 

SOURCE

­/appl/lib/lock.b

BUGS

The current implementation uses a pipe and thus two file descriptors for every lock.  On the other hand, when a process exists, garbage collection of file descriptors ensures that locks are relinquished. 

Plan 9  —  June 29, 2000

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026