6LVWHPDV&RQFXUUHQWHV ,9$EVWUDFFLyQGHPHQVDMHV &DUORV'HOJDGR.ORRV ÉUHDGH,QJHQLHUtD7HOHPiWLFD 8QLYHUVLGDG&DUORV,,,GH0DGULG SC-4 Copyright © C. Delgado Kloos 2000/01 1 5HVXPHQ ❚ &RPXQLFDFLyQSRUSDVRGHPHQVDMHV ❙ 3DVRGHPHQVDMHVDVtQFURQR HM VWUHDPV ❙ 3DVRGHPHQVDMHVVtQFURQRHM&63 ❚ $EVWUDFFLyQGHPHQVDMHV ❙ /ODPDGDDSURFHGLPLHQWRUHPRWR53& HM'3 ❙ 5HQGH]YRXV HM$GD SC-4 Copyright © C. Delgado Kloos 2000/01 2 1 $EVWUDFFLyQ GHPHQVDMHV ❚ 3ULPLWLYDVDQWHULRUHV ❙ RULHQWDGDVDGDWRV ❙ GHEDMRQLYHO ❙ SURFOLYHVDHUURUHV ❚ $EVWUDHPRV ❙ SULPLWLYDVRULHQWDGDVDDFFLRQHV ❙ XQDDFFLyQVHFRUUHVSRQGHFRQGRV FRPXQLFDFLRQHVRULHQWDGDVDGDWRV SC-4 Copyright © C. Delgado Kloos 2000/01 3 /ODPDGDDSURFHGL PLHQWRUHPRWR53& call proc end SC-4 Copyright © C. Delgado Kloos 2000/01 4 2 53&LGHD ❚ 1HOVRQ ❚ 3URYLVLyQGHXQVHUYLFLRHOSURFHGLPLHQWR UHPRWRDXQFOLHQWHHOTXHOODPD ❚ ,GHDDWUDFWLYD ❙ )iFLOGHHQWHQGHU ❙ )iFLOGHLPSOHPHQWDU Copyright © C. Delgado Kloos 2000/01 SC-4 5 53&LPSOHPHQWDFLyQ Cliente Servidor Llamada a proc. remoto Procedimiento remoto llamada resultado mensaje con resultado resultado Stub llamada Stub mensaje con llamada SC-4 Copyright © C. Delgado Kloos 2000/01 6 3 53&SUREOHPDV ❚ (MHFXFLyQ ❙ VHFXHQFLDOIiFLO ❙ SDUDOHODPiVFRPSOLFDGD ❚ 3DVRGHSDUiPHWURV ❙ FDOOE\YDOXH \FDOOE\YDOXHUHVXOW IiFLO ❙ FDOOE\UHIHUHQFH PiVFRPSOLFDGR SC-4 Copyright © C. Delgado Kloos 2000/01 7 '3 ❚ 'LVWULEXWHG3URFHVVHV ❚ 3HU%ULQFK+DQVHQ SC-4 Copyright © C. Delgado Kloos 2000/01 8 4 '36LQWD[LV Definición de proceso ❚ process nombre1 variables locales procedimientos comunes (globales) inicialización Definición de procedimiento ❚ proc nombre2 (entradas#salidas) variables locales Llamada de sentencia procedimiento ❚ call nombre1.nombre2(expr,vars) SC-4 Copyright © C. Delgado Kloos 2000/01 9 '3HME~IHU ❚ process buffer; mensaje:int; lleno:boolean; proc mete(n:int); when not lleno: mensaje:=n; lleno:=true end; proc saca(#n:int); when lleno: n:=mensaje; lleno:=false end; lleno:=false SC-4 Copyright © C. Delgado Kloos 2000/01 10 5 '3HM)LOyVRIRV ❚ UHVROXFLyQVLQUHVROYHUOD ❚ process sala; comiendo: set[5]int; KDPEUXQD ❚ process filo[5]; do true: ... {piensa} call sala.entr(THIS) ... {come} call sala.sale(THIS) end; SC-4 proc entr(i:int); when (not((i-1)mod 5 in comiendo) and (not((i+1)mod 5 in comiendo): comiendo:=comiendo+i end; proc sale(i:int); comiendo:=comiendo-i; comiendo:=[] Copyright © C. Delgado Kloos 2000/01 11 5HQGH]YRXV ❚ 8QUHQGH]YRXV HVFRPRXQ53& HQHOTXH ODOODPDGDHVVHUYLGDSRUXQSURFHVR\D H[LVWHQWHQRVHFUHD ❚ (VXQDJHQHUDOL]DFLyQGHOSDVRGH PHQVDMHVVtQFURQRDYHFHVDpVWHVHOH OODPDUHQGH]YRXV\DOUHQGH]YRXV UHQGH]YRXV H[WHQGLGR SC-4 Copyright © C. Delgado Kloos 2000/01 12 6 5HQGH]YRXV Bloqueo si llega antes Bloqueo si llega antes call in ni SC-4 Copyright © C. Delgado Kloos 2000/01 13 656HQWHQFLDin ❚ resource main() op f(x:int) process p var y:int; ... call f(y); ... end process q var z:int; ... in f(x)->z+:=x ni; ... end end SC-4 Copyright © C. Delgado Kloos 2000/01 14 7 65receive YVin ❚ receive f(v1,v2) ❚ HVHTXLYDOHQWHD ❚ in f(p1,p2)->v1:=p1; v2:=p2 ni ❚ 6LQHPEDUJR in...ni SHUPLWH IXQFLRQDOLGDGHVDGLFLRQDOHV ❙ DOWHUQDWLYDVDQLGDPLHQWR ❙ H[SUHVLRQHVGHVLQFURQL]DFLyQ ❙ H[SUHVLRQHVGHSODQLILFDFLyQ SC-4 Copyright © C. Delgado Kloos 2000/01 15 656HQWHQFLDin $OWHUQDWLYDV ❚ resource main() op f(x:int) op g(u:real) returns v:real process p1 var y:int; ... call f(y); ... end process p2 var w:real; ... w:=g(3.8); ... end SC-4 ❚ process q var z:int; ... in f(x)->z+:=x [] g(u) returns v-> v:=u*u-9.3 [] else->z:=0 ni ... q no espera si no end hay llamada pendiente end Copyright © C. Delgado Kloos 2000/01 16 8 656HQWHQFLDin $QLGDPLHQWR ❚ resource main() op swap(var x:int) process p1 var y:int; ... call swap(y); ... end process p2 var z:int; ... call swap(z); ... end SC-4 ❚ process q in swap(x1)-> in swap(x2)-> x1:=:x2 ni ni ... o al end revés end Copyright © C. Delgado Kloos 2000/01 17 656HQWHQFLDin (VSHUDV ❚ 6LFXDQGRXQDVHQWHQFLDin HVWiDWHQ GLHQGR DXQDOODPDGDUHFLEHRWUDpVWDVH TXHGDHVSHUDQGRHQXQDFRODGHHVSHUD ❚ /DVOODPDGDVGHODFRODVHYDQDWHQGLHQGR VXFHVLYDPHQWHHQRUGHQVLQHPEDUJR ❙ XQDH[SUHVLyQGHVLQFURQL]DFLyQSXHGHKDFHU QRVHOHFFLRQDEOHDXQDOODPDGD ❙ XQDH[SUSODQLILFDFSXHGHPRGLILFDUHORUGHQ SC-4 Copyright © C. Delgado Kloos 2000/01 18 9 656HQWHQFLDin ([SUGHVLQFURQL]DFLyQ ❚ in a(x) st c>0 -> ... ni ❚ in a(x) st x>0 -> ... ni ❚ in a(x) st x>0 -> ... [] b(y,z) st y=f(z) -> ... ni SC-4 ❚ var avail:=M do true-> in request() st avail>0 -> avail-[] release() -> avail++ ni Copyright © C. Delgado Kloos 2000/01 19 656HQWHQFLDin ([SUVLQFUHME~IHU ❚ resource buffer op mete(item:int) op saca() returns item:int body buffer(n:int) var b[0:n-1]:int var num:=0 var i:=0 var o:=0 SC-4 ❚ process worker do true-> in mete(item) st num<n ->b[i]:=item i:=(i+1)%n num++ [] saca() returns item st num>0 ->item:=b[o] o:=(o+1)%n num-ni od end end Copyright © C. Delgado Kloos 2000/01 20 10 656HQWHQFLDin ([SUGHSODQLILFDFLyQ ❚ 6HOHFFLyQGHODOODPDGDTXHVHDWLHQGH GHHQWUHODVTXHHVWiQHVSHUDQGRFRQ H[SUHVLyQGHVLQFURQL]DFLyQYHUGDGHUD ❚ 6HVHOHFFLRQDODTXHPLQLPL]DODH[SUGH SODQLILFDFLyQVLKD\YDULDVODPiVDQWLJXD ❚ 6LKD\YDULDVUDPDVTXHFXPSOHQODH[SU GHVLQFURQL]DFLyQVHHOLJHODRSHUDFLyQ FRQODOODPDGDPiVDQWLJXD\GHHQWUH HOODVODTXHPLQLPL]DODH[SUSODQLI SC-4 Copyright © C. Delgado Kloos 2000/01 21 656HQWHQFLDin ([SUGHSODQLILFDFLyQ ❚ in a(x) by x -> ... ni ❚ in a(x) st x mod 2=0 by -x -> ... ni ❚ in a(x) st x mod 2=0 by -x -> ... [] b(y,z) by y+z -> ... ni SC-4 ❚ do true -> in request(use_time) by use_time -> skip ni receive release() od Copyright © C. Delgado Kloos 2000/01 22 11 $GD ❚ 'LVHxRGHFRPLWpSRUHQFDUJRGHO 'HSDUWDPHQWRGH'HIHQVDGH86$ ❚ 8WLOL]DGRHQDSOLFDFLRQHVPLOLWDUHV DHURQiXWLFDVHWF ❚ 3ULPHUDVYHUVLRQHVILQDOHVGHORV ❚ (VWiQGDUGHVGH ❚ $GD SC-4 Copyright © C. Delgado Kloos 2000/01 23 $GDWDUHDV ❚ 7DUHDV ❙ (VSHFLILFDFLyQ 65 op task id is decls de entry end; ❙ VRQORVSURFHVRV ❙ HVSHFLILFDFLyQH 65 LPSOHPHQWDFLyQ proc ❙ ,PSOHPHQWDFLyQ FRPSLODEOHVSRU task body id is decls locales VHSDUDGR begin sentencias ❙ DUUD\VGHWDUHDV end id; ❙ SRVLEOHFUHDFLyQ GLQiPLFDGHWDUHDV Copyright © C. Delgado Kloos XVDQGRSXQWHURV SC-4 2000/01 24 12 65YV$GD ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ op in else st H[SUVLQFU ❚ byH[SUSODQLI ❚ QRKD\WLHPSRUHDO SC-4 entry select, accept otherwise when: H[SU VLQFU QRSXHGHXVDU SDUiPHWURV ❚ QRKD\ ❚ delay Copyright © C. Delgado Kloos 2000/01 25 $GDHM%~IHU task type BUFFER is entry procedure METE(E:in T) entry procedure SACA(E:out T) end BUFFER; task body BUFFER is B:array(0..N-1)of T; i,o:NATURAL range 0..N-1:=0; num:NATURAL range 0..N:=0; SC-4 begin loop select when num<n=> accept METE(E:in T) do B(i):=E; end; num:=num+1; i:=(i+1)mod N; or when num>0=> accept SACA(E:out T)do E:=B(o); end; num:=num-1; o:=(o+1)mod N; end select; end loop; end BUFFER; Copyright © C. Delgado Kloos 2000/01 26 13 5HQGH]YRXV ❚ 8QSURFHVRH[SRUWDRSHUDFLRQHVTXHSXHGHQVHU OODPDGDVSRURWURV ❚ (OVHUYLFLRGHXQDOODPDGDVHUHDOL]DVLQFRQRFHU DOTXHOODPD ❚ /DVOODPDGDVTXHHVSHUDQVHUVHUYLGDVVH DFXPXODQHQXQDFROD ❚ 8QDRSHUDFLyQSXHGHVHUVHUYLGDSRUYDULRV SURFHVRVLQFOXVRGHIRUPDGLVWLQWD ❚ 8QSURFHVRSXHGHVHUYLUYDULDVRSHUDFLRQHV SC-4 Copyright © C. Delgado Kloos 2000/01 27 5HVXPHQ ❚ 3P DVtQF XQLGLUDVtQFH[LVWH SURF ❚ 3P VtQF XQLGLUVtQFH[LVWH SURF ❚ 53& ELGLUVtQFFUHDSURF ❚ 5HQGH]YRXV ELGLUVtQFH[LVWHSURF SC-4 Copyright © C. Delgado Kloos 2000/01 28 14 5HVXPHQ Espera activa Semáforos RCCs PM asíncrono Monitores PM síncrono RPC SC-4 Rendezvous Copyright © C. Delgado Kloos 2000/01 29 5HVXPHQ65 ❚ 5HDOL]DFLyQGHOD OODPDGD ❙ callVtQFURQR ❙ sendDVtQFURQR SC-4 ❚ $WHQFLyQVHUYLFLRGH ODOODPDGD ❙ procFUHDFLyQGH SURFHVR ❙ in JHQHUDOL]DFLyQGH receiveSURFHVR HMHFXWiQGRVH Copyright © C. Delgado Kloos 2000/01 30 15 5HVXPHQ65 call send receive receive 3DVRGHPHQVDMHV VtQFURQR 3DVRGHPHQVDMHV DVtQFURQR Copyright © C. Delgado Kloos 2000/01 SC-4 31 5HVXPHQ65 call send in in ni ni 5HQGH]YRXV SC-4 3DVRGHPHQVDMHV DVtQFURQR Copyright © C. Delgado Kloos 2000/01 32 16 5HVXPHQ65 call send proc proc end end 53& SC-4 &UHDFLyQGLQiPLFD GHSURFHVR Copyright © C. Delgado Kloos 2000/01 33 2WURVOHQJXDMHV\PRGHORV ❚ ❚ ❚ ❚ ❚ ❚ 5HGHVGH3HWUL&&6/2726$&3 &RQFXUUHQW 3DVFDO&RQFXUUHQW&-DYD &/($1&0/ 3DUORJ &RQFXUUHQW3URORJ 9+'/ 9HULORJ8'/, 6WDWH&KDUWV6'/(UODQJ SC-4 Copyright © C. Delgado Kloos 2000/01 34 17 5HIHUHQFLDVJHQHUDO ❚ 1*HKDQL$0F*HWWULFN HGV&RQFXUUHQW 3URJUDPPLQJ:RNLQJKDP8.$GGLVRQ:HVOH\ UHFRSLODFLyQGHDUWtFXORVUHOHYDQWHVVREUHFRQFXUUHQFLD SC-4 Copyright © C. Delgado Kloos 2000/01 35 5HIHUHQFLDVVWUHDPV ❚ :%$FNHUPDQ'DWD)ORZ/DQJXDJHV,(((&RPSXWHU )HE ❚ *.DKQ7KH6HPDQWLFVRID6LPSOH/DQJXDJHIRU 3DUDOOHO3URJUDPPLQJ,QIRUPDWLRQ3URFHVVLQJ 3URF ,),3&RQJUHVV6WRFNKROP$PVWHUGDP1RUWK +ROODQG SC-4 Copyright © C. Delgado Kloos 2000/01 36 18 5HIHUHQFLDV&63'3 ❚ &$5+RDUH&RPPXQLFDWLQJ6HTXHQWLDO3URFHVVHV &RPP$&0$XJ ❚ &$5+RDUH&RPPXQLFDWLQJ6HTXHQWLDO3URFHVVHV (QJOHZRRG&OLIIV3UHQWLFH+DOO ❚ 3%ULQFK +DQVHQ'LVWULEXWHG3URFHVVHV$&RQFXUUHQW 3URJUDPPLQJ&RQFHSW&RPP$&01RY SC-4 Copyright © C. Delgado Kloos 2000/01 37 5HIHUHQFLDV/2726 ❚ ,62,QIRUPDWLRQ3URFHVVLQJ6\VWHPV 2SHQ6\VWHPV ,QWHUFRQQHFWLRQ /2726$)RUPDO'HVFULSWLRQ 7HFKQLTXH%DVHGRQWKH7HPSRUDO2UGHULQJRI 2EVHUYDWLRQDO%HKDYLRXU,6 ❚ 7%RORJQHVL(%ULQNVPD,QWURGXFWLRQWRWKH,62 6SHFLILFDWLRQ/DQJXDJH/2726HQ3(LMN&9LVVHUV 0'tD] HGV7KH)RUPDO'HVFULSWLRQ 7HFKQLTXH /27265HVXOWVRIWKH(635,76('263URMHFW $PVWHUGDP1RUWK+ROODQG SC-4 Copyright © C. Delgado Kloos 2000/01 38 19 5HIHUHQFLDV$GD ❚ -',FKELDK HWDO5DWLRQDOHIRUWKHGHVLJQRI WKH $GD SURJUDPPLQJODQJXDJH6,*3/$1 1RWLFHV ❚ ,625HIHUHQFH0DQXDOIRUWKH $GD 3URJUDPP LQJ/DQJXDJH $16,0,/67'$,62 WDPELpQ/1&6%HUOLQ6SULQJHU ❚ ,62 &KDQJHVWR $GD WR,62,(& ( SC-4 Copyright © C. Delgado Kloos 2000/01 39 5HIHUHQFLDV-DYD ❚ +0 'HLWHO3- 'HLWHO-DYD +RZWR3URJUDP 3UHQWLFH+DOO ❚ '/HD &RQFXUUHQW3URJUDPPLQJ LQ-DYD 'HVLJQ 3ULQFLSOHVDQG3DWWHUQV$GGLVRQ:HVOH\ ❚ 6-+DUWOH\&RQFXUUHQW3URJUDPPLQJ7KH -DYD 3URJDPPLQJ/DQJXDJH2[IRUG8QLY3UHVV SC-4 Copyright © C. Delgado Kloos 2000/01 40 20