Presentation is loading. Please wait.

Presentation is loading. Please wait.

Santa Claus – with Mobile Reindeer and Elves CPA 2008 (09/07/2008) Peter Welch ( ) Matt Pedersen ( )

Similar presentations


Presentation on theme: "Santa Claus – with Mobile Reindeer and Elves CPA 2008 (09/07/2008) Peter Welch ( ) Matt Pedersen ( )"— Presentation transcript:

1 Santa Claus – with Mobile Reindeer and Elves CPA 2008 (09/07/2008) Peter Welch ( ) Matt Pedersen ( )

2 MOBILE processes … Santa Claus …

3 A B D E C P Q S T R occam- suspend disconnected moved reconnected reactivated An occam- mobile process, embedded anywhere in a dynamically evolving network, may suspend itself mid- execution, be safely disconnected from its local environment, moved (by channel communication) to a new environment, reconnected to that new environment and reactivated. Mobile Process Types

4 occam- suspend disconnected moved reconnected reactivated An occam- mobile process, embedded anywhere in a dynamically evolving network, may suspend itself mid- execution, be safely disconnected from its local environment, moved (by channel communication) to a new environment, reconnected to that new environment and reactivated. A B D E C P Q S T R Mobile Process Types

5 occam- suspend disconnected moved reconnected reactivated An occam- mobile process, embedded anywhere in a dynamically evolving network, may suspend itself mid- execution, be safely disconnected from its local environment, moved (by channel communication) to a new environment, reconnected to that new environment and reactivated. A B D E C P Q S T R Mobile Process Types

6 occam- suspend disconnected moved reconnected reactivated An occam- mobile process, embedded anywhere in a dynamically evolving network, may suspend itself mid- execution, be safely disconnected from its local environment, moved (by channel communication) to a new environment, reconnected to that new environment and reactivated. A B D E C P Q S T R Mobile Process Types

7 occam- suspend disconnected moved reconnected reactivated An occam- mobile process, embedded anywhere in a dynamically evolving network, may suspend itself mid- execution, be safely disconnected from its local environment, moved (by channel communication) to a new environment, reconnected to that new environment and reactivated. (i.e. data values and code positions) since that is abstracted by its channel interface Upon reactivation, the process resumes from the same state (i.e. data values and code positions) it held when suspended. Its view of that environment is unchanged, since that is abstracted by its channel interface. The environment on the other side of that abstraction, however, will usually be different. any number of levels The mobile process may itself contain any number of levels of dynamically evolving parallel sub-network. Mobile Process Types

8 activepassive passive Mobile processes are entities encapsulating state and code. They may be active or passive. Initially, they are passive. activepassive The state of a mobile process can only be felt by interacting with it when active. When passive, its state is locked – even against reading. passiveactive activate (self) suspend move Mobile Process Types

9 passiveactivatedmoved movedpassiveactive movedactivated When passive, they may be activated or moved. A moved process remains passive. An active process cannot be moved or activated in parallel. activesuspends passive activated When an active mobile process suspends, it becomes passive – retaining its state and code position. When it moves, its state moves with it. When re-activated, it sees its previous state and continues from where it left off. passiveactive activate (self) suspend move Mobile Process Types

10 appletsagents Mobile processes exist in many technologies – such as applets, agents and in distributed operating systems. occam- denotationalrefinement occam- offers (will offer) support for them with a formal denotational and refinement semantics, safety and very low overheads. Process mobility semantics follows naturally from that for mobile data and mobile channel-ends. types variables We need to introduce a concept of process types and variables. Mobile Process Types

11 PROC TYPE IN.OUT.SUSPEND (CHAN INT in?, out!, suspend?): type PROC Process type declarations give names to PROC header templates. Mobile processes may implement types with synchronisation parameters only (i.e. channels, barriers, buckets, etc.) plus records and fixed-size arrays of the same. For example: type IN.OUT.SUSPEND in?, suspend? out!INT The above declares a process type called IN.OUT.SUSPEND. Processes implementing this will be given three channels by the (re-)activating host process: two for input ( in?, suspend? ) and one for output ( out! ), all carrying INT traffic. types variablesconnection interface Process types are used in two ways: for the declaration of process variables and to define the connection interface to a mobile process. Mobile Process Types

12 Mobile Process Example WHILE TRUE WHILE TRUE INT x: INT x: PRI ALT PRI ALT suspend ? x suspend ? x in ? x in ? x SEQ SEQ total := total + x total := total + x out ! total out ! total INITIAL INT total IS 0: -- local state INITIAL INT total IS 0: -- local state SUSPEND -- control returns to activator SUSPEND -- control returns to activator -- control resumes here when next activated -- control resumes here when next activated MOBILE PROC integrate.suspend (CHAN INT in?, out!, suspend?) : suspend in out integrate.suspend IMPLEMENTS IN.OUT.SUSPEND

13 Mobile Processes and Types type A process type may be implemented by many mobile processes – each offering different behaviours. variable undefinedsome mobile process defined A process variable has a specific process type. Its value may be undefined or some mobile process implementing its type. A process variable may be bound to different mobile processes, offering different behaviours, at different times in its life. When defined, it can only be activated according to that type. integrate.suspend IN.OUT.SUSPEND The mobile process from the last slide, integrate.suspend, implements the process type, IN.OUT.SUSPEND, defined earlier. Other processes could implement the same type.

14 process.out! p process.out ! p -- p is now undefined (cant move or activate it) -- p is now undefined (cant move or activate it) PROC A (CHAN IN.OUT.SUSPEND process.out!) : p := MOBILE integrate.suspend p := MOBILE integrate.suspend -- p is now defined (can move and activate) -- p is now defined (can move and activate) IN.OUT.SUSPEND p: IN.OUT.SUSPEND p: SEQ SEQ -- p is not yet defined (cant move or activate it) -- p is not yet defined (cant move or activate it) process.out A Mobile Process Example

15 PROC B (CHAN IN.OUT.SUSPEND process.in?, process.out!, CHAN INT in?, out!, suspend?) CHAN INT in?, out!, suspend?): WHILE TRUE WHILE TRUE IN.OUT.SUSPEND q: IN.OUT.SUSPEND q: SEQ SEQ... input a process to q... input a process to q... plug into local channels and activate q... plug into local channels and activate q... when finished, send it on its way... when finished, send it on its way process.in B process.out insuspend out Mobile Process Example

16 process.out ! q process.out ! q -- q is now undefined (cant move or activate it) -- q is now undefined (cant move or activate it) process.in ? q process.in ? q -- q is now defined (can move and activate) -- q is now defined (can move and activate) WHILE TRUE IN.OUT.SUSPEND q: IN.OUT.SUSPEND q: SEQ SEQ -- q is not yet defined (cant move or activate it) -- q is not yet defined (cant move or activate it) q (in?, out!, suspend?) q (in?, out!, suspend?) -- q is still defined (can move and activate) -- q is still defined (can move and activate) process.in B process.out insuspend out Mobile Process Example

17 CHAN IN.OUT.SUSPEND c, d: CHAN INT in, out, suspend:... other channels PAR A (c!) A (c!) B (c?, d!, in?, out!, suspend?) B (c?, d!, in?, out!, suspend?)... other processes... other processes … c in out suspend B d A

18 MOBILE processes … Santa Claus …

19 Santa repeatedly sleeps until wakened by either all of his nine reindeer (back from their holidays) or by a group of three of his ten elves (who have left their workbenches). If awakened by the reindeer, he harnesses each of them to his sleigh, delivers toys with them and finally unharnesses them (allowing them to go back on holiday). If awakened by a group of elves, he shows each of the group into his study, consults with them on toy R&D and finally shows each of them out (allowing them to go back to work). Santa should give priority to the reindeer in the case that there is both a group of elves and a group of reindeer waiting. J.A.Trono, A new exercise in concurrency, SIGCSE Bulletin 26(3), pp. 8-10, 1994.

20 First: a static network (classical occam, shared channels, barriers and partial barriers)

21 santa.reindeer reindeer.2.santa report Santa just.reindeer Reindeer (0) Reindeer (1) Reindeer (8)...

22 report Elf (0) Elf (1) Elf (9) Santa santa.elves (4) elves.2.santa just.elves (3)

23 santa.reindeer reindeer.2.santareport Santa just.reindeer Reindeer (0) Reindeer (1) Reindeer (8)...

24 report Elf (0) Elf (1) Elf (9) Santa santa.elves (4) elves.2.santa just.elves (3)

25 reportsanta.elves.b elves.2.santa just.elves.b p.bar (4) xp.bar (3) santa.elves.a just.elves.a... Elf (0) Elf (1) Elf (9) Santa

26 Second: a dynamic network (mobile channels) Deferred … (ask Adam!)

27 Third: a dynamic network (mobile processes)

28 compound (n.reindeer) gather (n.reindeer) santas grotto compound (n.elves) gather (g.elves) r.knocke.knockreportreport report reportreport reindeerreindeerreindeerreindeer elveselveselveselves

29 compound (n) report stationstationstation...

30 PROC station (VAL INT id, seed, kind, away.time, SHARED CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!) MOBILE AGENT agent: SEQ agent := MOBILE reindelf... initialise agent... loop (send agent; receive agent; run agent) : reportstation in out report A reindelf : either a reindeer or an elf

31 reportstation in out {{{ initialise agent CHAN AGENT.INITIALISE initialise:... some dummy channels PAR initialise ! id; seed; kind; away.time agent (initialise?, report!,...) }}} report A reindelf : either a reindeer or an elf initialise

32 reportstation in out initialise report PROC station (VAL INT id, seed, kind, away.time, SHARED CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!) MOBILE AGENT agent: SEQ agent := MOBILE reindelf... initialise agent... loop (send agent; receive agent; run agent) :

33 {{{ loop (send agent; receive agent; run agent) WHILE TRUE SEQ CLAIM out ! agent CLAIM in ? agent CHAN AGENT.INITIALISE dummy.init:... more dummy channels agent (dummy.init?, report!,...) }}} reportstation in out initialise report A reindelf : either a reindeer or an elf

34 reportstation in out PROC TYPE AGENT IS (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!,... ): report initialise reindelf (an agent) {{{ loop (send agent; receive agent; run agent) WHILE TRUE SEQ CLAIM out ! agent CLAIM in ? agent CHAN AGENT.INITIALISE dummy.init:... more dummy channels agent (dummy.init?, report!,...) }}}

35 PROC TYPE AGENT IS (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!,... ): MOBILE PROC reindelf (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!,... ) IMPLEMENTS AGENT INT id, seed, kind, away.time: SEQ initialise ? id; seed; kind; away.time WHILE TRUE SEQ CLAIM report ! away; kind; id... away time (random delay up to away.time) CLAIM report ! ready; kind; id SUSPEND -- move to gathering place... SUSPEND -- move to santas grotto... SUSPEND -- move to compound :

36 report initialise

37 reportstation in out initialise report A reindelf : either a reindeer or an elf PROC station (VAL INT id, seed, kind, away.time, SHARED CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!) MOBILE AGENT agent: SEQ agent := MOBILE reindelf... initialise agent... loop (send agent; receive agent; run agent) :

38 compound (n) reportstationstationstation...

39 compound (n.reindeer) gather (n.reindeer) santas grotto compound (n.elves) gather (g.elves) r.knocke.knock reportreport report reportreport reindeerreindeerreindeerreindeer elveselveselveselves

40 gather (n) knock reportinout PROC gather (VAL INT n, CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!, CHAN BOOL knock!) WHILE TRUE [n]MOBILE AGENT agent: SEQ SEQ i = 0 FOR n SEQ in ? agent[i]... plug in agent (let it make brief report) knock ! TRUE -- knock on santas door SEQ i = 0 FOR n out ! agent[i] knock ! TRUE -- wait for door to slam : report initialise

41 gather (n) knock reportinout {{{ plug in agent (let it make brief report) CHAN AGENT.INITIALISE dummy.init:... more dummy channels agent[i] (dummy.init?, report!,...) }}} report initialise

42 gather (n) knock reportinout MOBILE PROC reindelf (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!,... ) IMPLEMENTS AGENT... local state declarations SEQ... in station compound (initialise local state) WHILE TRUE SEQ... in station compound SUSPEND -- move to gathering place CLAIM report ! waiting; kind; id SUSPEND -- move to santas grotto... in santas grotto SUSPEND -- move to compound : report initialise

43 gather (n) knock reportinout report initialise PROC gather (VAL INT n, CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!, CHAN BOOL knock!) WHILE TRUE [n]MOBILE AGENT agent: SEQ SEQ i = 0 FOR n SEQ in ? agent[i]... plug in agent (let it make brief report) knock ! TRUE -- knock on santas door SEQ i = 0 FOR n out ! agent[i] knock ! TRUE -- wait for door to slam :

44 compound (n.reindeer) gather (n.reindeer) santas grotto compound (n.elves) gather (g.elves) r.knocke.knock reportreport report reportreport reindeerreindeerreindeerreindeer elveselveselveselves

45 santas grotto report santa... g.station g.station g.station g.station g.station g.station

46 report initialisesanta.asanta.b report g.station santa.a santa.b inout PROC grotto.station (SHARED CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!, SHARED CHAN INT santa.a!, santa.b!) WHILE TRUE MOBILE AGENT agent: SEQ CLAIM in ? agent CHAN AGENT.INITIALISE dummy.init: agent (dummy.init?, report!, santa.a!, santa.b!) CLAIM out ! agent :

47 PROC TYPE AGENT IS (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!, SHARED CHAN INT santa.a!, santa.b!): MOBILE PROC reindelf (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!, SHARED CHAN INT santa.a!, santa.b!) IMPLEMENTS AGENT... : report initialisesanta.asanta.b

48 santas grotto report santa... g.station g.station g.station g.station g.station g.station

49 PROC santa (CHAN INT elf.a?, elf.b?, CHAN INT reindeer.a?, reindeer.b?, CHAN BOOL elf.knock?, reindeer.knock?, SHARED CHAN SANTA.MESSAGE report) WHILE TRUE BOOL any: PRI ALT reindeer.knock ? any SEQ CLAIM report ! agent.ready; REINDEER.KIND... engage with reindeer elf.knock ? any SEQ CLAIM report ! agent.ready; ELF.KIND... engage with elves : report santae.knockr.knockr.ar.be.ae.b

50 PROC engage (VAL INT group.size, kind, CHAN INT agent.a?, agent.b?, CHAN BOOL knock?, SHARED CHAN SANTA.MESSAGE report!) INT id: BOOL any: SEQ SEQ i = 0 FOR group.size SEQ agent.a ? id CLAIM report ! greet; kind; id knock ? any -- slam the door SEQ i = 0 FOR group.size agent.b ? id CLAIM report ! engaged; kind... pause for a (random) while CLAIM report ! disengaged; kind SEQ i = 0 FOR group.size agent.a ? id SEQ i = 0 FOR group.size agent.b ?? id CLAIM report ! goodbye; kind, id :

51 santas grotto report santa... g.station g.station g.station g.station g.station g.station

52 report initialisesanta.asanta.b PROC grotto.station (SHARED CHAN MOBILE AGENT in?, out!, SHARED CHAN AGENT.MESSAGE report!, SHARED CHAN INT santa.a!, santa.b!) WHILE TRUE MOBILE AGENT agent: SEQ CLAIM in ? agent CHAN AGENT.INITIALISE dummy.init: agent (dummy.init?, report!, santa.a!, santa.b!) CLAIM out ! agent : report g.station santa.a santa.b inout

53 report g.station santa.a santa.b inout report initialisesanta.asanta.b MOBILE PROC reindelf (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!, SHARED CHAN INT santa.a!, santa.b!) IMPLEMENTS AGENT... local state declarations SEQ... in station compound (initialise local state) WHILE TRUE SEQ... in station compound SUSPEND -- move to gathering place... in the gathering place SUSPEND -- move to santas grotto... in santas grotto SUSPEND -- move to compound :

54 report g.station santa.a santa.b inout report initialisesanta.asanta.b {{{ in santas grotto CLAIM santa.a ! id -- say hello to santa CLAIM santa.b ! id -- sync with other agents -- and santa CLAIM report ! busy; kind; id CLAIM santa.a ! id -- wait for santa to finish -- working with me CLAIM report ! done; kind; id CLAIM santa.b ! id -- say goodbye to santa }}}

55 compound (n.reindeer) gather (n.reindeer) santas grotto compound (n.elves) gather (g.elves) r.knocke.knock reportreport report reportreport reindeerreindeerreindeerreindeer elveselveselveselves Design Summary

56 compound (n) reportstationstationstation... Design Summary

57 compound (n.reindeer) gather (n.reindeer) santas grotto compound (n.elves) gather (g.elves) r.knocke.knock reportreport report reportreport reindeerreindeerreindeerreindeer elveselveselveselves Design Summary

58 santas grotto report santa... g.station g.station g.station g.station g.station g.station Design Summary

59 MOBILE PROC reindelf (CHAN AGENT.INITIALISE initialise?, SHARED CHAN AGENT.MESSAGE report!, SHARED CHAN INT santa.a!, santa.b!) IMPLEMENTS AGENT... local state declarations SEQ... in station compound (initialise local state) WHILE TRUE SEQ... in station compound SUSPEND -- move to gathering place... in the gathering place SUSPEND -- move to santas grotto... in santas grotto SUSPEND -- move to compound : report initialisesanta.asanta.b Design Summary either a reindeer or an elf

60 Any Questions? A n y Q u e s t i o n s ?


Download ppt "Santa Claus – with Mobile Reindeer and Elves CPA 2008 (09/07/2008) Peter Welch ( ) Matt Pedersen ( )"

Similar presentations


Ads by Google