[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What I want in R^5RS

   From: Pavel Curtis <pavel@parc.xerox.com>
   Date: 	Wed, 4 Dec 1991 12:42:47 PST

   "Guillermo J. Rozas" writes: 
   > Some means of locking can be provided, but it need not (and probably should
   > not) be specific the file system.

   Hear, hear!

Here is what I use:

  (make-lock obj)				procedure

Returns a lock of name obj.  Then lock name is for use in error
reporting and appears in the printed representation of the lock.

  (lock! lck)					procedure

Locks lck for your use.

  (unlock! lck)					procedure

Unlocks lck.  If lck is already unlocked an error is signaled.

  (try-lock lck)				procedure

Returns #t if you now own the lock, #f otherwise.  Lck will be locked
if it is not already.

I did not find anything in the literature like try-lock but I find it
very useful for situations like scanning through a hash table (one
lock per bucket) when I don't care if I scan every bucket.  The use of
try-lock also makes mutual lockout much less likely.