atomic actions

Upload: truong-van-tuan

Post on 01-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Atomic Actions

    1/20

  • 8/9/2019 Atomic Actions

    2/20

    - . /01

    Aims To understand ho2 concurrent tasks can reliably cooperate in thepresence o3 errors45 hi5u l(m th6 n(o m( cc tc $% &ng th'i c th5 h8p tc m!t cch ng tin c)y trong s9 th5 hi n c*a cc l;i

    To introduce atomic actions and reco$erable atomicactions cc hot !ng nguy"n t# $( kh?i ph%c ch+ng

    To understand the need 3or asynchronous noti@cationtechni uesBi5u $> s9 c n thi6t c*a kD thu)t th?ng bo bEt &ng b!

    To link back to an FG course 3or HFGIJ signalsKi"n k6t $> li cc th* t%c c*a h i>u h(nh cho cc tLn hi u HFGIJ

    To understand the asynchronous e$ent handling model o3 Real.Time Ma$aBi5u $> m? hNnh O# lP cc s9 ki n bEt &ng b! c*a Real.Time Ma$a

    To understand the ATC model o3 the RTGMBi5u $> m? hNnh ATC c*a RTGM

    To understand the ATC model o3 the AdaBi5u $> m? hNnh ATC c*a Ada

  • 8/9/2019 Atomic Actions

    3/20

    1 . /01

    Atomic Actions Qoti$ationBot !ng nguy"n t# . 4!ng l9c

    The interaction bet2een - tasks has been eOpressed in terms o3 a single

    communication this is not al2ays the caseG9 tng tc giSa - task 8c trNnh b(y rU trong cc i>u khoVn c*a s9 truy>n th?ng tLn hi u i>u kh?nglu?n nh $)y trong cc tr'ng h8p

    W g , 2ithdra2al 3rom a bank account may in$ol$e a ledger process anda payment process in a se uence o3 communications to authenticatethe dra2er, check the balance and pay the moneyXL d%: R+t ti>n tY / t(i khoVn ngZn h(ng c th5 li"n uan t=i / u trNnh k6 ton $( u trNnh thanh tontrong / chu;i cc th&ng tin li"n lc 5 ch[ng th9c ng'i kP pht \Ch* t(i khoVn], ki5m tra s^ d $( trV ti>n

    It may be necessary for more than two tasks to interact to perform a required action.4i>u n(y c th5 l( c n thi6t cho nhi>u hn - task 5 tng tc th9c hi n / hot !ng

    The tasks in$ol$ed must see a consistent system stateCc tc $% li"n uan phVi Oem O_t trng thi h th^ng nhEt un ph` h8p

    ith concurrent tasks, it is all too easy 3or groups o3 tasks tointer3ere 2ith one otherX=i cc task &ng th'i, i>u n(y u n giVn cho nh m cc task can thi p $(o / task khc

    hat is re uired is 3or each group o3 tasks to eOecute their oint acti$ity asan indi$isible or atomic action4i>u c n thi6t l( cho m;i nh m cc task th9c thi hot !ng chung c*a ch+ng nh l( m!t hot !ng kh?ng th5phZn tch hay hot !ng nguy"n t#

  • 8/9/2019 Atomic Actions

    4/20

    . /01

    Atomic Actions e@nitionBot !ng nguy"n t# . hi ni m

    are not a2are o3 the eOistence o3 any other acti$e task,and no other acti$e task is a2are o3 the acti$ity o3 thetasks during the time the tasks are per3orming the actionh?ng nh)n th[c 8c s9 t&n ti c*a bEt kf / task hot !ng khc, $( kh?ng c task hot !ng khc nh)n th[c

    phm $ hot !ng c*a cc task trong th'i gian cc task th9c thi hot !ng \AC]do not communicate 2ith other tasks 2hile the action is being per3ormedh?ng giao ti6p $=i cc task khc trong khi hot !ng \AC] ang th9c thi

    can detect no state change eOcept those per3ormed by themsel$es and i3they do not re$eal their state changes until the action is completeC th5 pht hi n kh?ng c s9 thay i trng thi ngoi trY nhSng trng thi thay i b i n \s9 th9c thi c*an ] $( n6u n kh?ng t9 ti6t l! s9 thay i trng thi c*a n cho t=i khi hot !ng \AC] ho(n tEt

    can be considered, so 3ar as other tasks are concerned, to beindi$isible and instantaneous, such that the ejects on the systemare as i3 they 2ere interlea$ed as opposed to concurrentBot !ng l( nguy"n t# n6u cc task th9c thi n c th5 8c Oem O_t, cc task khc c li"n uan \cho t=i th'ii5m hi n ti], c th5 phZn chia $( &ng th'i, i>u tc !ng t=i h th^ng nh ki5u n6u ch+ng Oen k tri ng8c$=i &ng th'i

    An action is atomic if the tasks performing it:Mt hot ng c gi l nguyn t n u c!c task th"c thi n#:

  • 8/9/2019 Atomic Actions

    5/20

    . /01

    ested ActionsBot !ng l&ng nhau

    Although an atomic action is $ie2ed as being indi$isible, itcan ha$e an internal structureQ c d` hot !ng nguy"n t# c th5 8c Oem nh l( bEt khV phZn nhng ch+ng $ n c ki6n tr+c n!i b! c*a ch+ng

    To allo2 modular decomposition o3 atomic actions, thenotion o3 a nested atomic action is introducedCho ph_p phZn chia modular c*a hot !ng nguy"n t#, uan i5m $> hot !ng nguy"n t# l&ng nhau 8c gi=i thi u r ng:

    The tasks in$ol$ed in a nested action must be a subset o3 thosein$ol$ed in the outer le$el o3 the actionCc task li"n uan 6n / hot !ng l&ng nhau phVi l( / t)p h8p con c*a c*a cc task li"n uan m[c b"n ngo(i hot!ng

    I3 this 2ere not the case, a nested action could smugglein3ormation concerning the outer le$el action to an eOternal task6u Zy kh?ng phVi l( tr'ng h8p, / hot !ng l&ng nhau qtu&n th?ng tin li"n uan t=i h(nh !ng m[c b"n ngo(i cho

    / task b"n ngo(i

    The outer le$el action 2ould then no longer be indi$isibleB(nh !ng m[c b"n ngo(i sau s kh?ng c n b phZn chia

  • 8/9/2019 Atomic Actions

    6/20

    . /01

    Re uirements 3or Atomic Actions "u c u ^i $=i hot !ng nguy"n t#

    ell.de@ned boundariesRanh gi=i 8c Oc nh rU

    A start, end and a side boundaryh i u, k6t th+c $( / ranh gi=i cnh

    The start and end boundaries are the locations in each task2here the action is deemed to start and endvwt u $( k6t th+c ranh gi=i l( cc i5m c*a m;i task, ni h(nh !ng 8c coi l( bwt u $( k6t th+c

    The side boundary separates those tasks in$ol$ed in theaction 3rom those in the rest o3 the systemRanh gi=i cnh tch nhSng task li"n uan trong hot !ng $=i nhSng task c n li trong h th^ng

  • 8/9/2019 Atomic Actions

    7/20

    7 . /01

    Re uirements 3or Atomic Actions "u c u ^i $=i hot !ng nguy"n t#

    Indi$isibility \kh?ng phZn chia]o eOchange o3 in3ormation bet2een tasks acti$e inside andthose outside \resource managers eOcluded]h?ng trao i th?ng tin giSa - task ang hot !ng b"n trong $( b"n ngo(i \bao g&m cV cc t(i nguy"n uVnlP]

    The $alue o3 any shared data a3ter the actions is determinedby the strict se uencing o3 the actions in some order

  • 8/9/2019 Atomic Actions

    8/20

    | . /01

    Re uirements 3or Atomic Actions "u c u cho cc hot !ng nguy"n t#

    esting \l&ng nhau]Atomic actions may be nested as long as they do noto$erlap 2ith other atomic actionsCc hot !ng nguy"n t# c th5 8c l&ng nhau mi}n l( ch+ng kh?ng tr`ng l p $=i cc hot !ng nguy"nt# khc

    Fnly strict nesting is allo2ed \t2o structures are strictlynested i3 one is completely contained 2ithin the other]Ch~ cho ph_p l&ng ho(n to(n \ch~ +ng n"u - cEu tr+c m( / ci 8c l&ng ho(n to(n $(o ci kia n mho(n to(n]

  • 8/9/2019 Atomic Actions

    9/20

  • 8/9/2019 Atomic Actions

    10/20

    /0 . /01

    ested Atomic Actions

    time

    P6P1

    Action A

    Action B

    P5P4P3P2

  • 8/9/2019 Atomic Actions

    11/20

    // . /01

    action A with (P2, P3, . . .) do . . . -- can only communication with p2, P3 etc -- ch c th giao tip vi P2,P3,P4, P

    -- an! u"e local va#ia$le" -- v% "& !'ng c c $in c'c $end *+

    Kanguage Gtructure

    o mainstream language or FG supportsatomic actionh?ng c ng?n ngS chLnh th^ng hay h i>u h(nh h; tr8 cc hot !ng nguy"n t#

  • 8/9/2019 Atomic Actions

    12/20

  • 8/9/2019 Atomic Actions

    13/20

    /1 . /01

    Atomic Actions in Ada

    An atomic action in Ada 3or three tasks could beprogrammed 2ith a nested rende $ous, ho2e$er, this2ould not allo2 any parallelism 2ithin the actionBot !ng nguy"n t# trong Ada cho 1 task c th5 8c l)p trNnh $=i / rende $ous l&ng nhau, tuy nhi"n i>u n(y kh?ngcho ph_p cc h(nh !ng song song &ng th'i

    An alternati$e model is to create an action controllerand to program the re uired synchroni ationQ!t m? hNnh khc l( to / b! i>u khi5n hot !ng $( 5 chng trNnh &ng b! h a cc y"u c u

  • 8/9/2019 Atomic Actions

    14/20

  • 8/9/2019 Atomic Actions

    15/20

    / . /01

    Ada GtructureAction Controller

    $ole 1

    Entry Protocol

    action com"onent

    E%it Protocol

    lea&e

    $ole 2

    Entry Protocol

    action com"onent

    E%it Protocol

    lea&e

    $ole 3

    Entry Protocol

    action com"onent

    E%it Protocol

    lea&e

  • 8/9/2019 Atomic Actions

    16/20

    / . /01

    $ole 3$ole 2

    GtructureAction Controller

    $ole 1

    Entry Protocol

    action com"onent action com"onent action com"onent

    Entry Protocol

    E%it Protocol

    Entry Protocol

    E%it ProtocolE%it Protocol

    lea&e lea&elea&e

  • 8/9/2019 Atomic Actions

    17/20

  • 8/9/2019 Atomic Actions

    18/20

    /| . /01

    protected body *ction ont#olle# is entry /i#"t when not /i#"t 5e#e is begin /i#"t 5e#e 68 0#ue+ end /i#"t+ -- "imila#ly 9o# "econ!, thi#!

    entry /ini"he! when elea"e or /ini"he!: ount 8 3 is begin if /ini"he!: ount 8 ; then elea"e 68 /al"e+ /i#"t 5e#e 68 /al"e+

    econ! 5e#e 68 /al"e+ 0hi#! 5e#e 68 /al"e+ else elea"e 68 0#ue+ end if + end /ini"he!+ end *ction ont#olle#+

    Ada Code II

  • 8/9/2019 Atomic Actions

    19/20

  • 8/9/2019 Atomic Actions

    20/20