sunterlib/s48/concurrency
Anthony Carrico aeef47ae62 Moved package and interface definition to packages.scm. Generate load scripts. 2004-03-14 22:59:57 +00:00
..
AUTHORS Changed to new package system. 2004-03-10 17:07:41 +00:00
BLURB Automatically generate file DETAILS containing library details. 2003-03-11 06:13:58 +00:00
NEWS Changed to new package system. 2004-03-10 17:07:41 +00:00
README Fixed typos 2003-02-20 22:40:23 +00:00
packages.scm Moved package and interface definition to packages.scm. Generate load scripts. 2004-03-14 22:59:57 +00:00
pkg-def.scm Moved package and interface definition to packages.scm. Generate load scripts. 2004-03-14 22:59:57 +00:00
semaphore.scm Added two small utilities for threads 2003-01-28 12:48:57 +00:00
with-lock.scm Fixed bug: before-thunk needs to obtain the lock. 2003-03-05 14:32:06 +00:00

README

The package semaphores defines semaphores to be used this
threads. Semaphores are usually used to control access to a resource
by using a counter for the free slots of the resource.



(make-semaphore init) -> semaphore

Constructor for semaphores. INIT specifies the initial value of the
semaphore's counter.



(semaphore-wait sem) -> unspecific

Blocks the current thread until at the counter of the semaphore SEM is
at least one. It then decrements the counter and returns.


(semaphore-post sem) -> unspecific

Increments the counter of the semaphore SEM.


(with-semaphore-posted sem thunk)

Calls SEMAPHORE-WAIT on SEM before calling THUNK. When THUNK returns,
calls SEMAPHORE-POST on SEM and returns the return value of THUNK. If
the evaluation of THUNK causes a non-local exit, SEMAPHORE-POST is
also applied to SEM, likewise, if the control reenters the dynamic
extend of the evaluation of THUNK, SEMAPHORE-WAIT is called on SEM.



The structure WITH-LOCK exports the procedure WITH-LOCK as an
extension of the lock structure from Scheme 48.

(with-lock lock thunk)

This procedure obtains the requested lock, and then calls
(thunk). When thunk returns, the lock is released. A non-local exit
(e.g., throwing to a saved continuation or raising an exception) also
causes the lock to be released.

After a normal return from thunk, its return values are returned
by with-lock.