uwcse.location.objects
Class MultiReadSingleWriteLock

java.lang.Object
  |
  +--uwcse.location.objects.MultiReadSingleWriteLock

public class MultiReadSingleWriteLock
extends Object

This class implements a reader-writer lock allowing parallel reads but FIFO serialized atomic writes. Reads have priority in that when an active write releases its lock, pending reads will execute before other pending writes.

Methods should use a try-finally structure to request and release locks to avoid erroneous starvation or deadlock.

Multiple locks and deadlock: Note that in this implementation, attempts by a thread to acquire another lock when it already holds one will very likely result in deadlock.

Version:
$Revision: 1.6 $
Author:
Jeffrey Hightower

Nested Class Summary
static class MultiReadSingleWriteLock.UnitTest
          A unit test for the lock.
 
Constructor Summary
MultiReadSingleWriteLock()
          Create a multi-reader single-writer resource lock.
 
Method Summary
 void acquireReadLock()
          Requests the read lock and block until a read operation can be performed safely.
 void acquireWriteLock()
          Request the write lock and block until a write operation can be performed safely.
 void releaseReadLock()
          Release a previously acquired read lock.
 void releaseWriteLock()
          Release a previously acquired write lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiReadSingleWriteLock

public MultiReadSingleWriteLock()
Create a multi-reader single-writer resource lock.

Method Detail

acquireReadLock

public void acquireReadLock()
Requests the read lock and block until a read operation can be performed safely. This call must be followed by a call to releaseReadLock() when the read operation completes (typically in a finally{} block).

See Also:
releaseReadLock()

releaseReadLock

public void releaseReadLock()
Release a previously acquired read lock.

See Also:
acquireReadLock()

acquireWriteLock

public void acquireWriteLock()
Request the write lock and block until a write operation can be performed safely. Write requests execute FIFO but pending read requests have priority. When the write is finished, this call must be followed by a call to releaseWriteLock() (typically in a finally{} block).

See Also:
releaseWriteLock()

releaseWriteLock

public void releaseWriteLock()
Release a previously acquired write lock.

See Also:
acquireWriteLock()


This documentation is for the Location Stack v0.8. The latest distribution, the documentation, and the list of contributors to the Location Stack can always be found at http://portolano.cs.washington.edu/projects/location/

© Copyright 2004 University of Washington CSE