Question: 4 . Torrey Pines would like your help synchronizing surfers and the ocean. Using pseudocode, implement the class Surfing using locks and condition variables to
Torrey Pines would like your help synchronizing surfers and the ocean. Using pseudocode, implement the class Surfing using locks and condition variables to synchronize multiple surfer threads with one ocean thread do not manipulate interrupts Your solution also cannot change the lock, condition variable, or thread classes, and do not use data structures other than locks and condition variables to store references to threads.
You need only use pseudocode in your answers. Your pseudocode does not have to compile, and you can use whatever syntax you are most comfortable with the solutions use the Nachos syntax But it does have to look like code.
The Surfing class can be in one of two states, either breaking or calm. Surfer threads invoke the paddle method to indicate the direction, left or right, they would like to surf the break. When calm, surfer threads block until the next wave arrives. When breaking, surfer threads block if the wave is not breaking in their direction, and otherwise return immediately.
The ocean thread invokes the wave method indicating the direction the next wake is breaking left right, or both ways It changes the state to breaking and wakes up all surfer threads waiting to catch waves in that direction, or wakes up all threads if the wave is breaking in both directions. It invokes the done method to indicate that the wave is finished breaking, changing the state back to calm. The ocean thread alternates invoking wave and done and the state is initially calm.
class Surfing
enum State calm, breaking;
enum Direction LEFT, RIGHT, BOTH;
private variables...
Surfing
void paddle Direction dir invoked by surfer threads
void wave Direction dir invoked by the ocean thread
void done invoked by the ocean thread
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
