Class Fork

java.lang.Object
  |
  +--Fork

public class Fork
extends java.lang.Object

Every fork holds information about its owner -- the philosopher who currently uses it. A fork can be given to a philosopher and released via its synchronized methods only.

Author:
Jarda Kacer, Czech OS/2 User Group; email: jkacer@kiv.zcu.cz

Field Summary
private  Philosopher owner
           
 
Constructor Summary
Fork()
          Creates a new fork with no owner.
 
Method Summary
 void acquireFork(Philosopher philosopher)
          Gives the fork to the philosopher requiring it.
 Philosopher getOwner()
          Returns the fork's owner.
 void releaseFork(Philosopher philosopher)
          Releases the fork and wakes up a blocked thread waiting for the fork, if there is any.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

owner

private Philosopher owner
Constructor Detail

Fork

public Fork()
Creates a new fork with no owner.
Method Detail

getOwner

public Philosopher getOwner()
Returns the fork's owner.

acquireFork

public void acquireFork(Philosopher philosopher)
Gives the fork to the philosopher requiring it. If the fork already belongs to another philosopher, the calling thread is blocked until the fork is released.

releaseFork

public void releaseFork(Philosopher philosopher)
Releases the fork and wakes up a blocked thread waiting for the fork, if there is any.