Rendez-Vous - PowerPoint PPT Presentation

About This Presentation
Title:

Rendez-Vous

Description:

Channel port is a rendez-vous port (binary handshake) ... non-critical section */ od. init { run semaphore(); run user(); run user(); run user ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 8
Provided by: Muf7
Category:

less

Transcript and Presenter's Notes

Title: Rendez-Vous


1
Rendez-Vous
  • Logical extension of
  • chan buffer N of byte
  • is
  • chan port 0 of byte
  • Channel port is a rendez-vous port (binary
    handshake).
  • Two processes, a sender and receiver, can
    synchronise
  • e.g. port!2 is blocked until there is a
    corresponding
  • port?msg ready to execute
  • then both will synchronise.

2
Dijkstras Semaphore using Rendez-vous
  • define p 0
  • define q 1
  • chan sema 0 of bit
  • proctype semaphore()
  • byte count 1
  • do (count 1) -gt sema!p count 0
  • (count 0) -gt sema?v count 1
  • od
  • proctype user()
  • do sema?p
  • / critical section /
  • sema!v
  • / non-critical section /
  • od

3
Synchronous vs Asynchronous Communication
  • define msgtype
  • chan name x of byte,byte
  • proctype A()
  • name!msgtype(124)
  • name!msgtype(121)
  • proctype B()
  • byte state
  • name?state
  • init
  • atomic run A() run B() / created at the
    same time /
  • Behaviour
  • x0
  • A and B will synch on transfer of 124, then A
    will block.

4
An Interesting Way to Compute the Factorial
Function
  • Proctype fact(int n chan p)
  • / calculate factorial n, communicating result
    via p /
  • chan child 1 of int
  • / for result from fact n-1 /
  • int result
  • if (n lt 1) -gt p!1
  • (ngt2) -gt run fact(n-1, child)
  • child?result
  • p!(nresult)
  • fi
  • init / factorial 5 /
  • chan result 1 of int
  • int answer
  • run fact(5, result)

5
Assertions
  • Assertions are statements about the program state
    that can be embedded in the program.
  • assert (condition)
  • E.g. assert (state 1)
  • assert (x gt y)
  • Extremely useful! For
  • run-time behavioural audit
  • program invariants
  • But be careful,
  • assertions abort the program if the condition
    evaluates to 0, i.e. it is false.

6
Assertions
  • Common ways to use assertions
  • idle assert(arm up) ..
  • receiver assert (full(inchannel))
  • parcel 0 ..
  • sender assert (empty(outchannel))
  • parcel 1 ...
  • inchannel?x assert x last_value 1 ..

7
Factorial Function
  • Proctype fact(int n chan p)
  • / calculate factorial n, communicating result
    via p /
  • chan child 1 of int
  • / for result from fact n-1 /
  • int result
  • if (n lt 1) -gt p!1
  • (ngt2) -gt assert (empty child)
  • run fact(n-1, child)
  • assert (full(child))
  • child?result
  • p!(nresult)
  • fi
  • (assert full(p))
  • init / factorial 5 /
  • chan result 1 of int
Write a Comment
User Comments (0)
About PowerShow.com