Open main menu

lensowiki β

Changes

Computer Science/162/proj1

51 bytes removed, 04:42, 5 October 2008
m
Implementation: merge two "overview" sections...
==Boat.java==
===Implementation===
Algorithm for solving boat problem (high level):
If there are no children on Molokai or if there are no adults left on Oahu, two children from Oahu will pilot over and one will return to Molokai. If there is a child on Molokai, an adult will pilot over to Molokai and the child will bring the boat back to Oahu. This process, carried to completion eventually results in all of the adults and children on Molokai.
 
;New state variables (all shared)
{{c|<pre>lock = new Lock()
;Basic idea
If there are no children on Molokai or if there are no adults left on Oahu, two children from Oahu will pilot over and one will return to Molokai. If there is a child on Molokai, an adult will pilot over to Molokai and the child will bring the boat back to Oahu. This process, carried to completion eventually results in all of the adults and children on Molokai. Each thread will attempt to acquire the lock (which essentially represents control over the boat). If the thread can perform one of the tasks fitting for the current state of the world, it executes it. Otherwise, it will go to sleep on the condition variable corresponding to its current role and location.
;Algorithm details
1,277
edits