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

Info iconThis preview shows pages 1–9. 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 port - send and receive / selective receive rendezvous bidirectional comms - entry call accept . .. reply Models : channel : relabelling, choice & guards port : message queue, choice & guards 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 SlotCanvas display; Receiver(Channel<Integer> c, SlotCanvas d) {chan=c; display=d;} public void run() { try { Integer v=null; while (true) { ThreadPanel.rotate(180); if (v!=null) display.leave(v.toString()); v = chan.receive(); display.enter(v.toString()); ThreadPanel.rotate(180); } } catch (InterruptedException e){} } }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Concurrency: message passing 8
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/11/2010 for the course COS COS226 taught by Professor Klazar during the Spring '10 term at University of Pretoria.

Page1 / 26

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

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

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