ch10 - Chapter 10 Message Passing Concurrency: message...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Concurrency: message passing 1 ©Magee/Kramer 2 nd Edition Chapter 10 Message Passing
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: message passing 2 ©Magee/Kramer 2 nd Edition Message Passing Concepts :   synchronous  message passing -  channel     asynchronous  message passing -  port   -  send  and  receive  /  selective receive       rendezvous bidirectional comms -  entry   -  call  and  accept . .. reply   Models :   channel   port   entry     port   channel Practice :  distributed computing (disjoint memory)  threads and monitors  (shared memory)
Background image of page 2
Concurrency: message passing 3 ©Magee/Kramer 2 nd Edition   send (e, c ) -   send the value  of the expression e to channel  c The process calling the send  operation is  blocked  until the  message is received from the  channel. 10.1 Synchronous Message Passing - channel Channel   c Sender send (e, c ) Receiver v= receive ( c )   v = receive ( c )    - receive a  value into local variable v from  channel  c . The process calling the  receive operation is  blocked   waiting until a message is sent to  the channel.  cf. distributed assignment   v = e   one-to-one
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: message passing 4 ©Magee/Kramer 2 nd Edition synchronous message passing - applet A sender communicates with a receiver using a single channel . The sender sends a sequence of integer values from 0 to 9 and then restarts at 0 again. Channel<Integer> chan = new Channel<Integer>(); tx.start( new Sender(chan,senddisp)); rx.start( new Receiver(chan,recvdisp)); Instances of SlotCanvas Instances of ThreadPanel
Background image of page 4
Concurrency: message passing 5 ©Magee/Kramer 2 nd Edition Java implementation - channel The implementation of Channel is a monitor that has synchronized access methods for send and receive . public class Channel<T> extends Selectable { T chan_ = null; public synchronized void send(T v) throws InterruptedException { chan_ = v; signal (); while (chan_ != null) wait (); } public synchronized T receive() throws InterruptedException { block(); clearReady(); //part of Selectable T tmp = chan_; chan_ = null; notifyAll (); //should be notify() return(tmp); } } Selectable is described later.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: message passing 6 ©Magee/Kramer 2 nd Edition Java implementation - sender class Sender implements Runnable { private Channel<Integer> chan; private SlotCanvas display; Sender(Channel<Integer> c, SlotCanvas d) {chan=c; display=d;} public void run() { try { int ei = 0; while (true) { display.enter(String.valueOf(ei)); ThreadPanel.rotate(12); chan.send(new Integer(ei)); display.leave(String.valueOf(ei)); ei=(ei+1)%10; ThreadPanel.rotate(348); } } catch (InterruptedException e){} } }
Background image of page 6
Concurrency: message passing 7 ©Magee/Kramer 2 nd Edition Java implementation - receiver class Receiver implements Runnable { private Channel<Integer> chan; private
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

ch10 - Chapter 10 Message Passing Concurrency: message...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online