1 / 19

Reactive Programs Design

Reactive Programs Design. Reactive Programs. Initiate actions in response to events. Basic events are: External - generated by the environment. Process - generated by running actions. Thus, typical instruction: when e [ while C] initiate A. action. condition. activating event.

shamus
Download Presentation

Reactive Programs Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Reactive Programs Design

  2. Reactive Programs • Initiate actions in response to events. • Basic events are: • External - generated by the environment. • Process - generated by running actions. Thus, typical instruction: when e [whileC]initiateA action condition activating event • e can be logical expression of basic events, • C represents a program state (internal variables)

  3. Actions • self-terminating programs. • no internal synchronization with the environment • termination of an action execution is an internal event • Two types: • Synchronous actions - Executed in no time w.r.t. the environment clock. • Asynchronous actions - Their executions may take some time units.  a sequence of synchronous actions is synchronous. Synchrony hypothesis: Synchronous actions take zero time.

  4. Practical Execution Model

  5. Reactive Program Design Formalism when e [whileC]initiateA initial actions Execution of async. actions activating event condition actions

  6. Reactive Program Design Formalism asynchronous actions A system under design is specified over: • E - a set of external events. • A – a set of program actions. A = Async Aasync synchronous actions • Async ,Aasync are disjoint sets • Assume actions return no value (extension to finite multiple values {v1,…,vm} is straight forward).

  7. Action Events • With every action aA we define the events: @a – initiate execution of a, a!–termination of an execution ofa a–interrupting a (only for aAasyn ) Notation: • @A = { @a | aA } • A! = {a!, a | aA } • Obs = E A! • For aAsyn @a, a! occur at the same time instant, hence use a as a single event.

  8. Transition System (TS) over E, A  , S, T, sinit, A init  = 2Obs2@A A init2@A   = ,where 2Obs,2@A (-pre(), -post()) sinitS initial state set of states T: S  S total on S • A behavior0,1,…is executable by TS iff • 0=, A init  • s0 s1 s2 …s.t. s0=sinit andT(si,i)= si+1 i=0,1,… The language accepted by TS isthe set of all executable beaviors.

  9. Example: XR control E={ Tin, Tout }, A={ Open, Close, Go, Stop} Ainit = {@open, stop} Sinit = {Opening }  =,{@open, stop}, {open!},, {Tin},{@close}, {close!},{go},… synchronous

  10. Real Time Programs • Initiate actions in response to events. • Specify durations to implement delaysand timeouts. • Basic events are: • External - generated by the environment. • Process - generated by running actions. • Timing - indicate time-periods expiration. Thus, typical instructions are still of the form: when x [whileC]initiateA but there is a special (async’) action:"waitn” action activating event condition time units

  11. Clocks as a Timing Formalism A clockcis a variable over Dc = {} [0,nc] With every clock c, ·   the term c=ncis a clock event. ·   the terms reset(c), stop(c) are sync. clock actions. Informal semantics: • c=  indicates the clock is disabled (initial value) • reset(c) – enables c and sets it to 0 • Enabled clock increases over [0,nc] at fixed rate c’=1 • stop(c) – disables c (sets it to ) • c=ncis generated when c reaches nc. Then, c becomes disabled, (unless the transition includes an action reset(c))

  12. Timed Transition System (TTS) A Timed Transition System over • E - a set of external events. • A – a set of program actions. • C ={c1,…,ck}– a finite set of clocks. is a TS , S, T, sinit,A initdefined over EC,AC where EC= E  {ci=nci| ciC} --clock events over C. AC= A{reset(ci), stop(ci)| ciC} -- clock actions over C.  = 2Obs2@(AC)where Obs=EC(AC)!  However behaviors are extended to provide time semantics

  13. Example TTS Suppose it is requiredthat if gateopening or closing does not end within9 sec. then thesystem must activate an alarmsignal and stop functioning.

  14. Time Progress Given a set of clocks C ={c1,…,ck}, a C-state is an assignment  = (1,2,…, k) s.t.jDcj, j=1,…,k Transition are labeled by: (,’)  - reflects clocks update by the time elapsed since last transition occurred. ’- reflects clocks update due to transition timing actions (reset, stop) and events.

  15. a/reset(c) Examples: [, ’] with a single clock c wherenc=7 [-,] [,0] c=7 [-,3] [7,] after 4 t.u. c=7/reset(c) [-,3] [7,0] b/stop(c) [-,2] [4,] after 2 t.u. b/reset(c) [-,2] [4,0]

  16. Timed Behavior A timedsequence: (0,[0, ’0],t0) (1,[1, ’1],t1) … where: • 0,1,…  • i, ’i are clock-states • tiN, titi+1, and nN.j s.t. tjn, i=1,2,…

  17. [ij,’ij] [i+1j,’i+1j] i+1j’ij(ti+1ti) ti+1 ti Consistent Behavior Atimed behavior(0,[0, ’0],t0) … is consistent iff: • 0 = , A init , 0j, j=1,…,k , t0=0 0 if reset(cj)post(i) • ’ij= if stop(cj)post(i) or ij = ncj ij otherwise • ti+1ti min{ ncj-’ij | ’ij, j=1..k } • if ’ij theni+1j’ij (ti+1ti) • cj=ncjpre(i) iff ij ncj cj=ncj [ij,’ij] [mj, ’mj 0] [kjncj, ’kj] tm tk ti ncjtktm

  18. Semantics of TTS A consistent behavior(0,[0, ’0],t0) (1,[1, ’1],t1) … of a TTSover EC,AC is executableiff there exists an infinite state sequence: s0 s1 s2 … such that s0=sinit and for every i=0,1,…, T(si, i)= si+1 The language accepted by TTS is the set of all executable beaviors.

More Related