nachos.threads
Class Lock

java.lang.Object
  extended by nachos.threads.Lock

public class Lock
extends Object

A Lock is a synchronization primitive that has two states, busy and free. There are only two operations allowed on a lock:

Also, only the thread that acquired a lock may release it. As with semaphores, the API does not allow you to read the lock state (because the value could change immediately after you read it).


Constructor Summary
Lock()
          Allocate a new lock.
 
Method Summary
 void acquire()
          Atomically acquire this lock.
 boolean isHeldByCurrentThread()
          Test if the current thread holds this lock.
 void release()
          Atomically release this lock, allowing other threads to acquire it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lock

public Lock()
Allocate a new lock. The lock will initially be free.

Method Detail

acquire

public void acquire()
Atomically acquire this lock. The current thread must not already hold this lock.


release

public void release()
Atomically release this lock, allowing other threads to acquire it.


isHeldByCurrentThread

public boolean isHeldByCurrentThread()
Test if the current thread holds this lock.

Returns:
true if the current thread holds this lock.