DOC PREVIEW
Duke CPS 110 - Lecture

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OutlineInterprocess Communication – Messages (API-level)IssuesSend and Receive5 DP – Direct Send/Receive Message Passing Between PhilosophersPowerPoint PresentationSlide 7Slide 8Slide 9Client / ServerExample: Time Service (kernel-based)Example: Time Service (via Messages)Client / Server with ThreadsHiding Message-Passing: RPCRemote Procedure Call - RPCSlide 16Slide 17Slide 18Slide 19Slide 205DP via RPC with Fork ManagerExample: Time Service via RPCRPC IssuesPractice BreakSlide 26Slide 27Garden MonitorSlide 29Garden Server (using threads and monitor)Slide 311Outline•Objective: –Message Passing•Administrative details: –Sign up for demo slots on Demo Scheduler–Check for demo location with grader–Submit details will be posted on the newsgroup–“Freeze” your code at midnight in a subdir you won’t touch until the demo (same as submitted)–Check for changes on the website (in schedule, problem sets, etc)2Interprocess Communication – Messages (API-level)•Assume no explicit sharing of data elements in the address spaces of processes wishing to cooperate/communicate.•Essence of message-passing is copying (although implementations may avoid actual copies whenever possible). •Problem-solving with messages - has a feel of more active involvement by participants.3Issues•System calls for sending and receiving messages with the OS(s) acting as courier.–Variations on exact semantics of primitives and in the definition of what comprises a message.•Naming - direct (to/from pids), indirect (to distinct objects - e.g., mailboxes, ports, sockets)–How do unrelated processes “find” each other?• Buffering - capacity and blocking semantics.•Guarantees - in-order delivery? no lost messages?4Send and Receive Messaging combines55 DP – Direct Send/Receive Message Passing Between PhilosophersPhilosopher 0(thinking)Philosopher 1Philosopher 2Philosopher 3(eating)Philosopher 4Forkplease?6Philosopher 0(thinking)Philosopher 1Philosopher 2Philosopher 3(eating)Philosopher 4Umm. Oh yeah.7Philosopher 0(thinking)Philosopher 1Philosopher 2Philosopher 3(eating)Philosopher 4Forkplease?8Philosopher 0(thinking)Philosopher 1Philosopher 2Philosopher 3(eating)Philosopher 4Forkplease?I’ll ignorethat requestuntil I’m done9Philosopher 0(thinking)Philosopher 1Philosopher 2Philosopher 3(eating)Philosopher 4Forkplease?Forkplease?10Client / Serverserver->send(request)11Example: Time Service(kernel-based)12Example: Time Service (via Messages)13Client / Server with Threads14Hiding Message-Passing: RPC15Remote Procedure Call - RPC•Looks like a nice familiar procedure callP0result = foo(param);P1Receive16Remote Procedure Call - RPC•Looks like a nice familiar procedure callP0result = foo(param);please do foo for P0with paramP1Receiveblockedhere17Remote Procedure Call - RPC•Looks like a nice familiar procedure callP0result = foo(param);please do foo for P0with paramP1Receiver = foo(param);// actual callblockedhere18Remote Procedure Call - RPC•Looks like a nice familiar procedure callP0result = foo(param);P1Receiver = foo(param);// actual callReplyreturningr to P0blockedhere19Remote Procedure Call - RPC•Looks like a nice familiar procedure callP0result = foo(param);P1Receiver = foo(param);// actual callReplyreturningr to P020Remote Procedure Call - RPC•Looks like a nice familiar procedure callP0result = foo(param);P1Receiver = foo(param);// actual callReply215DP via RPC with Fork Manager•Looks like a nice familiar procedure callPhilosopher0result = PickupForks (0);Fork ServerReceiver = proc(param);// explicit queuingwhen necessaryReply22Example: Time Service via RPC24RPC Issues25Practice BreakLarry, Moe, and Curly are planting seeds. Larry digs the holes. Moe then places a seed in each hole. Curly then fills the hole up.There are several synchronization constraints:–Moe cannot plant a seed unless at least one empty hole exists, but Moe does not care how far Larry gets ahead of Moe.–Curly cannot fill a hole unless at least one hole exists in which Moe has planted a seed, but the hole has not yet been filled. Curly does not care how far Moe gets ahead of Curly.–Curly does care that Larry does not get more than MAX holes ahead of Curly. Thus, if there are MAX unfilled holes, Larry has to wait.–There is only one shovel with which both Larry and Curly need to dig and fill the holes, respectively.Sketch out the pseudocode for the 3 threads which represent Larry, Curly, and Moe using whatever synchronization/communication method you like.26Larry (){while (TRUE) { P(holes); P(shovel); dig; V(shovel); V(empty); }}Moe (){while(TRUE){ P(empty); seed empty hole; V(seeded); }}semaphore holes = MAX;semaphore shovel = 1;semaphore empty, seeded = 0;Curly (){while(TRUE){ P(seeded); P(shovel); fill hole; V(shovel); V(holes); }}27Larry (){while (TRUE) { garden->allowdigging();dig;garden->donedigging(); }}Moe (){while(TRUE){ garden->allowseeding();seed empty hole;garden->doneseeding(); }}Curly (){while(TRUE){ garden->allowfilling();fill hole;garden->donefilling(); }}28Garden MonitorLock garden_gate;Condition shovel_free, empty_holes, filled_holes, not_too_far_ahead;Void allowdigging() {garden_gate.Acquire();while (holes >= MAX) not_too_far_ahead.Wait(garden_gate);while (!shovel)shovel_free.Wait(garden_gate);holes ++; shovel = FALSE;garden_gate.Release();}Void donedigging() {garden_gate.Acquire();empty++; shovel=TRUE;empty_holes.Signal(garden_gate);shovel_free.Signal(garden_gate);garden_gate.Release();}Void allowseeding() {garden_gate.Acquire();while (empty == 0)empty_holes.Wait(garden_gate);garden_gate.Release();}Void doneseeding() {garden_gate.Acquire();empty--; filled++;filled_holes.Signal(garden_gate);garden_gate.Release();}29Void allowfilling() {garden_gate.Acquire();while (filled==0)filled_holes.Wait(garden_gate);while (!shovel)shovel_free.Wait(garden_gate);filled --; shovel = FALSE;garden_gate.Release();}Void donefilling() {garden_gate.Acquire();holes--; shovel=TRUE;not_too_far_ahead.Signal(garden_gate);shovel_free.Signal(garden_gate);garden_gate.Release();}30Garden Server(using threads and monitor)While (1){ReceiveRequest(msg);thread->fork(handler, msg);}Void handler (msg){garden->msg.function();SendReply(msg.requester);exit();}31Larry (){while (TRUE) {garden_server->RPC(allowdigging);dig;garden_server-> RPC(donedigging); }}Moe (){while(TRUE){garden_server-> RPC(allowseeding);seed empty hole;garden_server-> RPC(doneseeding); }}Curly


View Full Document

Duke CPS 110 - Lecture

Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?