CS101 Package Problem Set Javadocs

cs101.util.semaphore
Class BS

java.lang.Object
  extended bycs101.util.semaphore.BS

public class BS
extends java.lang.Object

This class implements simple binary semaphores in java.
Interface is bs.request(), bs.release().

Copyright 1996 Massachusetts Institute of Technology

Version:
$Id: BS.java,v 1.2 2003/09/23 15:35:17 gus Exp $
Author:
Lynn Andrea Stein, las@ai.mit.edu

Constructor Summary
BS()
          If no argument is supplied, the semaphore is created in its free state.
BS(boolean initVal)
          If the constructor is passed a boolean value, the semaphore will be initialized with this value (true => in use, false => free).
 
Method Summary
 void release()
          Releases the semaphore.
 void request()
          Requests the semaphore.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BS

public BS(boolean initVal)
If the constructor is passed a boolean value, the semaphore will be initialized with this value (true => in use, false => free).

Parameters:
initVal - Initial value for semaphore. (true => in use)

BS

public BS()
If no argument is supplied, the semaphore is created in its free state.

Method Detail

request

public void request()
Requests the semaphore. If the semaphore is currently busy, causes the requesting process to wait() until the semaphore is release()d. Unlike java.lang.Object.wait(), the requesting process is not suspended if the semaphore is currently free.

See Also:
release(), Object.wait()

release

public void release()
Releases the semaphore. Any objects currently wait()ing on the semaphore are notify()d (and one of them will be granted the semaphore). Unlike java.lang.Object.notify(), the semaphore is also freed so that if there are no wait()ing objects, the next object to request() the semaphore will receive it.

See Also:
request(), Object.notifyAll()

CS101 Package Problem Set Javadocs