Вы находитесь на странице: 1из 245

atsoC ad leicaM osleC

Sistemas Operacionais

.PX/0002 swodniW on e xuniL on airmem ed aicnreG .lautriv airmeM .oatnemgeS

.oanigaP .gnippawS .sievirav seitraP .saxif seitraP .socisb sotiecnoC

airmeM ed aicnreG .7

.kcoldaeD rativE .kcoldaeD ed oneverP .kcoldaed ed oceteD .kcoldaeD od soipcnirP

kcoldaeD .6

.IPM .otnemidecorP ed atomeR adamahC .opurG me oacinumoC .oacinumoC ed savitimirP .snegasneM ed acorT .adahlitrapmoC airmeM

snegasneM ed acorT rop sossecorP ertne oacinumoC .5

.serotinoM .acitrC oigeR .lanoicidnoC acitrC oigeR .siaicepsE seurtsnI sorofmeS .autM osulcxE ed somtiroglA .aicnrrocnoC ad soipcnirP

sossecorP ed oazinorcniS .4

.PX/0002 swodniW on e xuniL lanoicarepo ametsiS on otnemanolacsE .salelarap saniuqm me sossecorp ed otnemanolacsE .otnemanolacse ed somtiroglA .socisB sotiecnoC

otnemanolacsE .3

.)sdaerht( sevel sossecorP .aicnrrocnoC ed oacificepsE .aicnrrocnoC ed seidnoC .setnerrocnoC sossecorP

setnerrocnoC sossecorP .2

.ametsiS ed sadamahc e sepurretnI .PX/0002 swodniW od e xuniL lanoicarepo ametsis od aruturtsE .sianoicarepO sametsiS sod otnemanoicnuf e aruturtsE .sianoicarepO sametsiS sod oulovE

sianoicarepO sametsiS sod otnemanoicnuF e oulovE .1

oirmuS

.PX/0002 swodniW on e xuniL on soviuqra ed aicnreG .soviuqra ed otnemahlitrapmoC .soviuqra ed oarepucer

e otnemanezamrA .soirteriD .soviuqra ed oazinagrO .socisB sotiecnoC

soviuqra ed aicnreG .8

ed samargorp soirv metsixe sodamargorpitlum soN .oucexe me oirusu ed amargorp ocin mu etsixe sodamargorponom sianoicarepo sametsis soN oamargorpitluM e oamargorponoM .oirusu oa etnerapsnart etnematelpmoc ,ocirfirep on sodad ed oavarg ed oarepo amu me lanoicarepo ametsis olep adizudart res oviuqra mu me atircse ed oarepo amU .lanoicarepo ametsis olep sadaicnereg sacigl sedaditne os euq ,soviuqra moc

matart soirusu so ,olpmexe roP .lautriv aniuqm amu odnairc ,maicnereg euq erawdrah ed sosrucer so sodot mazilautriv sianoicarepo sametsis sO .sodad soa osseca ed somsinacem solep e adas e adartne ed sovitisopsid sod aicnreg alep od ,soviuqra ed aicnreg alep ,airmem ed aicnreg alep mu ,rodassecorp .oacilpa

aicnreg

alep

levsnopser

,sosrucer

ed

rodaicnereg

ed samargorp sod otnemivlovnesed o arap esab a mecenrof e rodatupmoc od sosrucer so sodot malortnoc euq samargorp os sianoicarepo sametsiS

OS

sod

oaruturtse a e sovitejbo

od oircsed

ed ritrap a ,sianoicarepo sametsis sod oulove a atneserpa olutpac etsE

aruturtsE .otnemanoicnuf e sovitejbO .sianoicarepO sametsiS sod oulovE

1.1 Evoluo dos Sistemas Operacionais


.ametsis ed sadamahc sad otnemanoicnuf a ,sianoicarepO sametsiS sod oreS otnemanoicnuf .snegiro saus so mbmat sodatneserpa .ametsiS ed sadamahC .sianoicarepO sametsiS sod

Sistemas Operacionais Funcionamento dos 1 Evoluo e

mu

,airmem

ed

rodaicnereg

mu

,sovitisopsid

sod

srevirD

,sepurretnI

ed rodatarT iussop oazinagro aus mE .olelarap me ,soirusu ed samargorp solpitlm ed oucexe a atropus odamargorpitlum lanoicarepo ametsis mU

odamargorponoM lanoicarepO ametsiS

sepurretnI ed rodatarT

sovitisopsiD sod revirD

soviuqrA ed rodaicnereG

samargorP ed rodaicnqeS

soirusU ed samargorP

.odatucexe res a rassap e samargorp ed rodaicneqes olep odagerrac res amargorp ortuo mu ,oucexe ad onimrt oA .airmem an oirusu ed amargorp ocin mu

;amargorp ovon mu ratucexe a essap ametsis o euq moc za f ,amargorp mu

.seamrofni ed oarepucer a e otnemanezamra o oirusu oa odnitimrep ,soviuqra ed

;ocirfirep ed essalc adac arap revird mu etsixE .adas e adartne ed

;sepurretni sad

:socigl setnenopmoc ocnic rop odamrof .odamargorponom lanoicarepo ametsis mu ed oazinagro a artsom riuges a arugif A .aentlumis oucexe me oirusu

otnematart olep levsnopser OS od erawtfos :sepurretnI ed rodatarT

searepo sad oucexe alep sievsnopser :sovitisopsid sod srevirD

ametsis od oatnemelpmi alep levsnopser :soviuqrA ed rodaicnereG

ed oucexe ad onimrt oa ,euq oludm :samargorp ed rodaicneqeS

etsixE

.oucexe me amargorp o atneserper :soirusu ed samargorP

mu

ed

avreser

a aizaf oirusu adaC

.aniuqm a

erbos

elortnoc

otelpmoc

mahnit e relbmessa me sotircse mare samargorp sO .erawdrah o etnematerid ramargorp oirssecen are e lanoicarepo ametsis maussop on saniuqm

satsE .rodatupmoc o rasu aitimrep sehl euq o ,erawdrah od otnemicehnoc ednarg on mu maussop euq euq e ,sotnemapiuqe so sod otnemivlovnesed mare soirusu

mavahlabart

serodasiuqsep

mbmat

sO .oazilitu arap saroh ed oacram ed ameuqse mu moc e sodazilaicepse etnematla soirusu moc ,siaunam etnemlatot mare sametsis soriemirp sO

sianoicarepO sametsiS sod oulovE

odamargorpitluM lanoicarepO ametsiS

opurretni ed serodatarT sovitisopsid sod srevirD airmem ed rodaicnereG sossecorp ed rodaicnereG soviuqra ed rodaicnereG samargorp ed rodaicneqeS soirusu ed samargorP

.odamargorpitlum lanoicarepo ametsis mu ed setnenopmoc so etnemacitameuqse artsom riuges a arugif A .odatucexe res a assap e odanoiceles ossecorp ovon mu ,ossi spa

,e ossecorp od odidep oa etnerefer otnematart ed anitor a atucexe lanoicarepo ametsis o ,sosac setseN .otneve ortuo mugla ed aicnrroco amu a rarepse euq ta

etissecen euq

ta uo

,adas

e adartne

ed

oarepo

eticilos

uo ,opmet otrec mu rop atucexe amargorp adaC

.oucexe me samargorp

so ertne odubirtsid rodassecorp od opmet o odamargorpitlum ametsis muN .oucexe me soirusu ed samargorp solep e samargorp ed rodaicneqes mu rop ,soviuqra ed rodaicnereg mu rop ,samargorp ed orapsid e oeles alep levsnopser ,rodanolacse mu iussop euq sossecorp ed rodaicnereg

:etniuges o rotinom od otnemanoicnuf O

.ocitmotua rodaicneqes mu rop

e sotnemidecorp ed ogidc meussop euq ,)ogidc ed oazilituer( acetoilbib ed sanitor rotinom arap rop O ,adas e adartne ed ed srevird ad solep ,etnemacisab ,odamrof

.samargorp

oucexe mu

ocitmotua etnediser

otnemaicneqes mU

rezaf

odibecnoc

oelcn

oneuqep

rotinom

.etnediser rotinom ed otiecnoc od otnemivlovnesed o i of ,avitacifingis siam ,oulove artuo amU

.sacitmetam ,olpmexe rop ,sanitor sairprp saus sa e socirfirep soa osseca ed srevird soirprp sues revlovnesed oirusu adac ed edadissecen a mare setnetsixe setnatropmi samelborp sortuO

.onamuh rodarepo olep ,etnemlaunam otief are oucexe ed otnemaicneqes o ,ossid mlA .zev adac ed amargorp mu odatucexe are e oirusuonom odnes avaunitnoc aniuqm a ,otnatne oN .etnemroiretna sodatic

,c

e ,

b ,a

samelborp so avanimile onamuh rodarepo mu ed ogerpme O

.socitlop serotaf rop adanimreted res medro atse odnedop ,sodibecer mare euq me medro an sodatucexe mare samargorp so erpmes men euq etnemlarutaN .sodatluser so ragertne e sol-tucexe ,soirusu sod samargorp setnerefid so rebecer ed onuf a moc ,onamuh rodarepo mu ed ooda iof adagerpme oulos amU

.aniuqm a razilitu aidop zev rop oirusu mu etnemoS

)d

;oirusu ovon mu ed adagehc a ta asoico aicenamrep aniuqm a e ohlabart ues o odavreser opmet od setna avanimret oirusu O )c

;asoico aniuqm a moc ,amargorp o odnaruped odavreser opmet od otium avatsag oirusu O )b

;aroh/atad avon amu me aferat a raemocer me racilpmi airedop euq o ,odavreser opmet on ohlabart ues o ranimret aiugesnoc on oirusu O )a

:sovitacifingis mare setnetsixe samelborp sO .rodatupmoc od oazilitu ed opmet odanimreted

.samargorp sod oucexe sairssecen seamrofni sa etnediser rotinom oa mecenrof euq ,elortnoc ed setrac

ed osu od oudortni iof samelborp setse arap oulos amU .sodad sod amargorp od ogidc riugnitsid omoc e ortuo ed amargorp mu riugnitsid omoc ,relbmessA uo nartroF ,loboC ,olpmexe rop ,ratucexe a amargorp od azerutan a rebas omoc mare etnediser rotinom moc setnetsixe samelborp sO

.oamargorponom ed oledom mu ed ,otnatrop ,es-atarT .oucexe arap odagerrac amargorp ovon mu onimrt ues spa etnemos euq

odnes ,etnematelpmoc odatucexe amargorp adac ,ameuqse etseN .soirusu sod samargorp so retnoc arap artuo e rotinom o retnoc arap amu ,setrap saud me adidivid rodatupmoc od airmem a etnediser rotinom moC

... ,sosserpmi ,acitngam atif me sodavarg os sodatluser sO

.8

;odatucexe amargorp O

.7

;airmem a arap ocitngam robmat od amargorp o erefsnart e odanoica rodatupmoc O .6

;)ocitngam robmat mu ,olpmexe rop( odipr siam ocirfirep mu arap ,sodarufrep setrac ed arotiel amu moc ,setrac sod amargorp o erefsnart onamuh rodarepo O .5

;onamuh rodarepo oa sodarufrep setrac so ragertnE

.4

;megaugnil ad odnamoc adac a setnednopserroc setrac so rarufreP

.3

;)nartroF .xE( oamargorp ed megaugnil amu me ramargorP

.2

;oulos ad acigl a rarobalE

.1

setniuges so os amargorp mu ed oucexe a arap sossap so ,etnediser rotinom moC

;pooL ot og

;ratucexe

;oucexe arap ogidc o ragerrac :pooL

amargorp od ogidc o odnetnoc setrac ; nartroF rodalipmoc o ragerrac ; oirusu o racifitnedi ;

1 otrac N TF$ 1 emaNresu BOJ$

:etniuges o odamargorpitlum hctab lanoicarepo ametsis mu me odatucexe res a samargorp ed aicnqes ed olpmexe mU

.airmem an setnediser samargorp so ertne odubirtsid UPC ed opmet o odnes ,opmet omsem oa airmem an soditnam os samargorp soirv e e ,rodarepo os od onevretni sacitsretcarac a mes ,aicnqes ed amu me sodatucexe ,sametsis oa

sodapurga

samsem

samargorp rotinom ed

so

setseN

.etnemroiretna

odatneserpa

etnediser

otiecnoc

oulove amu matneserper sodamargorpitlum hctaB sianoicarepo sametsiS

sodamargorpitlum hctaB sianoicarepO sametsiS

.etnemlaicneqes sodatucexe os samargorp so siop ,odazilitubus adnia ecenamrep rodatupmoc o lauq on ,odamargorponom hctaB lanoicarepo ametsis mu etnediser rotinom O

.samargorp sod oucexe a rarapsid ,airmem an samargorp so ragerrac ,elortnoc ed setrac so raterpretnI :sedadilanoicnuf setniuges sa iussop etnediser rotinom o ,elortnoc ed setrac moC

.amargorp ed mif acidni :JOE$ ;sodad ed oicni acidni :ATAD$ ;odatucexe res reved amargorp o euq acidni :NUR$

oamargorp ed megaugnil ad sodnamoc


;oucexe arap airmem a arap odagerrac res eved amargorp o euq acidni :DAOL$ ;nartroF megaugnil a euq acidni :NTF$ ;amargorp mu ed oicni o acidni :BOJ$

01

)gnirahs emiT( odahlitrapmoc opmet ed sianoicarepo sametsiS

.rodassecorp od agertne a arap samargorp ed oeles ed sacitlop ritsixe e meved e oucexe acitlop me samargorp eveD so arap airmem e ed oarebil ed

oacola

ed

amu

ritsixe

.otnemanolacse

airme m

aicnreg os sodamargorpitlum sametsis so arap siatnemadnuf senuf sauD

amargorp od lanif ;

JOE$ n sodad ed otrac - - 2 sodad ed otrac

sodad ed setrac ; amargorp o ratucexe ; odalipmoc amargorp o ragerrac ;

1 sodad ed otrac NUR$ DAOL$ n otrac - - 2 otrac

amargorp od ogidc o odnetnoc setrac ; nartroF rodalipmoc o ragerrac ; oirusu o acifitnedi ; amargorp od lanif ;

1 otrac N TF$ 2 emaNresu BOJ$ JOE$ n sodad ed otrac - - 2 sodad ed otrac

sodad ed setrac ; amargorp o ratucexe ; odalipmoc amargorp o ragerrac ;

1 sodad ed otrac NUR$ DAOL$

n otrac - - 2 otrac

11

laer opmeT ed sianoicarepO sametsiS

.oirusu o moc rigaretni ed onuf a iussop euq ,sodnamoc ed rodaterpretni mu rop o t i ef oucexe ed otnemaicnqes o ,mroP

.odamargorpitlum lanoicarepo ametsis mu ed somsem so os odahlitrapmoc opmet ad osu ed lanoicarepo medop ametsis mu ed me setnenopmoc mu sO .aniuqm ,soirusu

r e z af

,lanimret

adac

,etnemaenatlumis

soirv ,ossid mlA ues o atucexe e

.rodatupmoc o moc aterid oacinumoc me amargorp alipmoc ,atide oirusu O .otnemapiuqe o moc egaretni

oirusu o siop ,hctab sianoicarepo sametsis so moc es-odnarapmoc ,ronem otium amargorp mu ed otnemivlovnesed ed o p m et o ,sametsis setseN

;pool ot oG

oucexe arap amargorp o agerraC

;ratucexe a amargorp od emon o odnetnoc odnamoc ed ahnil a l :pool

:lauq on ,onrete pool mu atucexe sodnamoc ed rodaterpretni o ,odahlitrapmoc o p m et ed sianoicarepo sametsis soN

.oirusuitlum lanoicarepo ametsis mu .rodatupmoc od osu o mahlitrapmoc soirusu sotium euq etnatropmi otcepsa ortuo mU .amargorp ues

o atucexe e alipmoc etnemataidemi oirusu o ,missA .lanimret o rel a atlov sodnamoC ed rodaterpretnI o ,odnamoc mu ed oucexe a spA .oucexe arap agerrac o e odatucexe res a amargorp od emon o odnetnoc odnamoc ed ahnil a l euq ,sodnamoC ed rodaterpretnI mu iussop ametsis O .sianimret ed osu o moc atief otnemapiuqe o e oirusu o ertne oaretni A .etnemataidemi satsopser O sa ebecer ed e ametsis o e oa o seisiuqer ertne enil etembus no oirusu

.oatupmoc etsixe

ametsis .0791

oirusu son

oacinumoc e 0691 sona sO

amu sod

,setseN

sona

seralupop o p m et ed

maranrot

es

oicni on

marigrus odahlitrapmoc

sianoicarepo

sametsis

21

edeR ed sianoicarepO sametsiS

.sodaicossa otse siauq soa sotneve so merroco odnauq sodarapsid os atucexe euq sossecorp so euq otsiv ,sodnamoc ed rodaterpretni men oucexe ed rodaicneqes iussop oN .oacilpa sodauqeda ,sominm res medop euq sossecorp ed rodaicnereg mu e airmem sod ed rodaicnereg so mu ,setnetsixe soa socirfirep soa sodaicossa ed

,socirfirep

srevird

,sotneve

sodaicossa

,sepurretni

rodatart o os laer opmet ed lanoicarepo ametsis mu ed setnenopmoc sO

.cte ,siairtsudni seacilpa samugla me ,acitbor an sodazilitu os sametsis siaT .opmet ed seirtser meussop on euq seacilpa a sodacided sametsis os

metsys emit-laer tfoS

.otneve od aicnrroco a rednopser reved ametsis o euq me odanimreted opmet ed olavretni mu ,otnatrop ,etsixE .rerroco redop etnedica mu ,opmet ed odanimreted odorep mu me odanoica rof on oronos lanis o eS .atsirotom oa atrela ed ,oronos lanis mu ,olpmexe rop ,odareg

res e otneve etsed aicnrroco a razilanis reved euq lanoicarepo ametsis olep odaterpretni res euq lanis mu rareg ,adartse amu ed siaretal san adatnip acnarb axiaf a ratceted ed sezapac os levmotua mu me sodacoloc serosnes euq rasnep es-edop ,olpmexe roP .rerroco on ossi es adacovorp res redop evarg ahlaf amu euq ed anep bos ,odanimreted opmet ed olavretni mu me ,amrof atrec amu ed ,otneve mu a rednopser edadissecen alep odaziretcarac

metsys emit-laer draH mU .metsys emit-laer tfoS

uo

metsys emit-laer draH

omoc sodacifissalc res medop laer opmet ed sianoicarepo sametsis sO

.atsopser ed sianis sodaivne os e odibecer lanis od otnematart oa etnednopserroc ,oa amu adatucexe e sodasilana os sodad so ,rodatupmoc oa sodaivne os euq sodad mateloc serosnes ,sametsis setsed sotium mE .cte ,oaiva an ,acitbor an ,lairtsudni ossecorp ed mu mu ed elortnoc s i at sodasu ,sacidm snegami ,saciftneic amu seatnemirepxe me ovitisopsid sametsiS

elortnoc ralortnoc

omoc arap

,adacided os laer

oacilpa opmet ed

sianoicarepo

31

.SFN od oazinagro a artsuli riuges a arugif A .etneilc oa rahnimacne a euq S FV olep adatart res edno ,etnaticilos odon

oa odaivne res odatluser o e otomer ametsis on adazilaer otne res oarepo A .)otnemidecorP ed atomeR adamahC( CPR mu ed amrof a

bos ,etnatsid ametsis oa adaivne amsem a odnes megasnem amu adareg ,otomer oirterid uo oviuqra o eS .etneilc oa odaivne odatluser

o e adatucexe oarepo a ,lacol oirterid uo oviuqra mu ed es-odnatarT . ) S F V( mu a metsyS eliF lautriV ed odanimoned uo ametsis erbos od etnenopmoc amU

adahnimacne

soirterid

soviuqra

oarepo

.soviuqra soa osseca mahnag ,megatnom ed oarepo alep ,setneilC

:etniuges a acisb aidi A

.srevres elif so ertne oacinumoc a e srevres elif

so aicnereg ,etnemasicerp siaM .seatse ed loop oa etnecnetrep seatse sa ertne soviuqra ed otnemahlitrapmoc o etimrep euq ametsis mu SFN O

.acisf oazilacol aus ed etnemetnednepedni soviuqra soa osseca o etimrep euq ,)metsyS eliF krowteN(

SFN o ,sodubirtsid soviuqra ed ametsis mu iussop euq ,siraloS nuS eder ed lanoicarepo ametsis ed ovitacifingis olpmexe mU .soviuqra soa osseca o e serodassecorp setnerefid so ertne oacinumoc a metimrep euq senuf ed mu otnujnoc ed ritrap mu a ed oaroprocni res a moc eder ,lanoicidart ed lanoicarepo ametsis ametsis mU

odurtsnoc

edop

lanoicarepo

.artuo arap aniuqm amu ed sol-vom arap sacifcepse searepo ratucexe e soviuqra sod oazilacol a recehnoc atissecen

oirusu o ,ossid mlA .otomer nigol ed sodnamoc moc ,etnematicilpxe zaf es aniuqm artuo amu a otomer osseca O .osserpmi ed rodivres mu ,olpmexe rop ,sosrucer odnahlitrapmoc e lanoicarepo ametsis oirprp ues o odnador amu adac ,oacinumoc ed eder amu rop sadagilretni saniuqm ed otnujnoc mu rop adamrof odnes omoc otsiv res edop eder ed lanoicarepo ametsis mU

soviuqra ed ametsis mu mahlitrapmoc serodivres e setneilc ed oeloC

;soirterid so matropxe serodivreS

41

.)oxiaba arugif( soirterid uo soviuqra uo soviuqra atropmi atropxe ale es arodivres aniuqm amU .soirterid

uo atnom ale es SFN etneilc aniuqm amU .oirusu

oa etnerapsnart e oviuqra od acisf oazilacol ad etnednepedni sadatucexe os etirw e daer searepo sA .eder an odilv oviuqra ed rodacifitnedi mu euq ,edoN-V mu anroter odinifed meb mu iussop tnuom e oarepo A .rodivres/etneilc olocotorp sametsis atropus SFN O

soengoreteh

SFN od otnemanoicnuf lareG osiV

Local

Virtual File System

Operaes sobre arquivos

Distante RPC Call RPC reply

51

.SFN od arutetiuqra ad lareg osiv amu atneserpa riuges a arugif A

. lacol oviuqra o es laer soviuqra ed ametsis on odaepam lautriv soviuqra ed ametsis O

;oelcn on SFV aruturtse amu ednopserroc odatnom soviuqra ed ametsis adac A

; ). . , S O D ,xinU( soviuqra ed ametsis ed sopit setnerefid a osseca etimreP

:sacitsretcarac setniuges sa iussop euq ,SFV on odartnec SFN od otnemanoicnuf O

.serodivres soirv ed etneilc res edop aniuqm amu e setneilc saniuqm sairv ret edop arodivres aniuqm amu ,rodivres etnemacinu ,etneilc etnemacinu ,rodivres e etneilc res edop ametsis mU

SFN od lareG osiV

rodivreS

etneilC

atropxE

atropmI

;ametsis od oelcn on odatnemelpmI

o o o

61

sodot odnalortnoc ,lanoicarepo ametsis ocin mu e aniuqm acin amu etsixe euq osserpmi a soirusu soa ecerefo odubirtsid lanoicarepo ametsis mU

.oacinumoc ed sahnil ed svarta atief serodassecorp so ed o a ertne oacinumoc on e o a e airmem airprp aus iussop ed ,serodassecorp

otnujnoc revomorp riubirtsid ed

,rodassecorp socisf

adaC

.sosrucer soirv

otnemahlitrapmoc oatupmoc ovitejbo O

serodassecorp lanoicarepo

ertne mu ed

odubirtsid

ametsis

sodubirtsiD sianoicarepO sametsiS

SFN od arutetiuqrA

CPR

ocsiD

CPR

ocsiD

rodivreS SFN SF lacoL

etneilC SF lacoL SFN

SFV ecafretnI

SFV ecafretnI

ametsis ed adamahC rodivreS

etneilC

71

.)riuges a arugif( serodassecorp ed eder ad rodassecorp reuqlauq rop adasseca res edop euq airmem amu etsixe mumoc airmem moc salelarap saniuqm saN

.adubirtsid airmem uo mumoc airmem ret odnedop ,etnednepedni amrof ed odnarepo rodassecorp mu ed siam rop satsopmoc os salelarap saniuqM

salelaraP saniuqM arap sianoicarepO sametsiS

.odatcenoc tse lauq an aniuqm

.otomer

.lanoicarepo ametsis ocin

:os odubirtsid lanoicarepo ametsis mu ed sotisiuqer snuglA .)adahlitrapmoc lautriv airmem moc(

otomer etirw mes

e otomer daer

searepo rop uo )airmem ed otnemahlitrapmoc ed acort rop atief serodassecorp mu atucexe ad so ertne

setneibma(

snegasnem

oacinumoc a e adac me

lanoicarepo

ametsis ed oelcn ametsis mu

rodassecorp sosrucer so

,odubirtsid

lanoicarepo

mE

.eder

aicnrapsnarT

mu moc ,aniuqm acin amu essitsixe omoc oirusu o araP

osseca ed aicnrapsnarT

uo lacol osrucer o es rebas ratissecen eved on oirusu O

oazilacol ed aicnrapsnarT

;oazilacol odanoicaler res eved on osrucer od emon O

ad etnemetnednepedni osrucer o rasseca redop eved oirusu O

81

:odamargorpitluM rodassecorpinU ametsiS mu ed soa seralimis os sarodassecorpitlum saniuqm arap lanoicarepo ametsis mu ed sovitejbo sO

adubirtsiD airmeM moc alelaraP aniuqM

.)riuges a arugif( serodassecorp sortuo sod airmem osseca iussop on rodassecorp mu e airmem airprp aus iussop rodassecorp adac adubirtsid airmem moc salelarap saniuqm saN

mumoC airmeM moc alelaraP aniuqM

p0

M0

p0

Memria

p1

M1

p1

2p

;sosrucer raicnereG

.levn otla ed aniuqm amu ed oartsba a oirusu oa revorP

M2 pn

91

amu

iussop

ametsis

ed

opit

e ts E

.sacitrc

sees

setnerefid

odnasseca

mu adac ,serodassecorp solpitlm rop odasseca res edop OS O :ocirtmiS

.ametsis od olagrag o odnes aunitnoc ertsem o euq megatnavsed lapicnirp A . ksat amu ed alelarap oucexe etimreP

;sodazilitu etnematelpmoc os serodassecorp so sodoT

:os megadroba atsed snegatnav sA .atucexe o zev rop rodassecorp mu e ,acitrc oes amu omoc odatart orietni OS O :etnautulf ertseM

.olagrag mu ranrot es edop ertsem O ;agrac atium moc acif on etnemlamron ertsem O ;atucexe sa ertsem o etnemos euqrop ametsis ed sadamahc sad oazilaireS

:os megadroba atsed snegatnavsed sA .ossecorp ocin mu ed alelarap oucexe a ritimrep ed otaf o e ratnemelpmi e ratejorp ed edadilicaf os oarugifnoc atsed snegatnav sA

.siamed soa sodatucexe meres a sossecorp so iubirtA ;ametsis ed sadamahc sa sadot atarT

:ametsis od sutats o arotinom )ertsem o( rodassecorP mU :ovarcsE/ertseM .ocirtmiS e etnautulf ertseM ,ovarcse/ertseM :mumoc airmem moc salelarap saniuqm arap sianoicarepo sametsis arap sacisb searugifnoc s r t metsixE

.sossecorp solpitlm ed alelarap oucexe ariedadrev odnatropus ,rodassecorpinu sametsis

son aicnrrocnoc oisopo me ,ocisf omsilelarap meussop )SOM( mumoc airmem moc sarodassecorpitlum saniuqm arap sianoicarepo sametsis sO

mumoc airmem moc salelarap saniuqm arap sianoicarepo sametsiS

02

ed onuf A .alelarap aniuqm ad odon adac me mu

,setnarepooc

siacol

slenrekorciM ed otnujnoc mu rop otsopmoc otnatrop olelaraP lenrekorciM mU .rodivres ovon mu ratnecserca atsab oivres ovon mu ratnecserca araP .rodivres/etneilc olocotorp mu moc odroca ed arienam amsem ad sodasseca os ametsis od sosrucer sO .edadiraludom a e edadilibisnetxe a os

lenrekorciM mu ed snegatnav sA .sodatluser so aivne e oaticilos a atucexe rodivres O .oivres o odnaticilos soviuqra ed etnereg rodivres oa etneilc od megasnem amu me zudart es oviuqra mu ed arutreba a ,olpmexe roP .serodivres sossecorp rop sodarugessa os euq socisslc soivres

sod muhnen ecerefo oN

.airmem ed aicnreg ed e sossecorp ed aicnreg

ed ,sossecorp ertne oacinumoc ed oelcn mu etnemlaicnesse lenrekorciM mU .lenrekorciM atid megadroba an etsisnoc oulos artuo amU

.olelarap ocitlonom oelcn mu amrof setnarepooc socitlonom soelcn ed otnujnoc O .setnatsid socisslc soivres soa osseca o e seacinumoc ed aicnreg a maroprocni es lauq oa ocitlonom oelcn mu iussop rodassecorp adaC .acisslc arienam ed odazinagro res edop olelarap lanoicarepo ametsis ed oelcn mU .adas e adartne ed e soviuqra ed ed me ed aicnreg aicnreg uo omoc ed soivres e ratnecserca adnia ed edop es ossi A .airmem

mbmat

oazinorcnis mu me e

,setnerefid ertne

serodassecorp oacinumoc ed aicnreg

rodassecorp uo

omsem

sossecorp oairc

,setnatsid

siacol

oiurtsed

:sossecorp

ed soivres ecerefoe rodassecorp adac me atucexe euq oelcn mu iussop adubirtsid airmem moc salelarap saniuqm arap lanoicarepo ametsis mU

adubirtsid airmem moc salelarap saniuqm arap sianoicarepO sametsiS

.etnemetnerrocnoc sadatucexe os ametsis ed sadamahc satium me euq etnatropmi res assop etnematla euq lenrek otcepsa mu ed mU .)etnartneer( euq olelarap

odatucexe

atissecen

,ratnemelpmi

e ratejorp ed licfid siam oazinagro amu ed ,otnatne on ,es-atarT .ossecorp ocin mu ed alelarap oucexe a etimrep e litsrev siam oarugifnoc

12

.lanoicarepo ametsis mu ed otnemanoicnuf omse m o o azitameuqse od oxiaba an arugif sodad A so .ratucexe odnatsE

etnemavon

redop

,amargorp

aer

.amargorp od sodad ed aer a arap raipoc so lanoicarepo ametsis o ,sreffub ed aer an rof eS .lanoicarepo ametsis olep adaicnereg sreffub ed aer an uo uoticilos euq amargorp od sodad ed aer an ,lapicnirp airmem an martnocne es oirusu od amargorp olep sodaticilos sodad so ,olpmexe etseN .opurretni ad otnematart ed anitor amu etucexe lanoicarepo ametsis o euq moc

raf euq e rodassecorp olep aditnes res euq ,opurretni amu rareg edop ocirfirep od rodalortnoc o ,ratelpmoc es aicnrefsnart a odnauQ .oivres od

odidep on odamrofni airmem ed oeredne o arap sodad sod aicnrefsnart a ocirfirep od rodalortnoc oa raticilos euq lanoicarepo ametsis olep adatucexe onuf amu a rednopserroc euq ametsis ed adamahc amu rop adazilaer res oirusu ed amargorp on arutiel ed oarepo amu ,olpmexe roP .soivres ed oaticilos matneserper euq ,sotneve a megaer sianoicarepo sametsis sO

sianoicarepO sametsiS sod otnemanoicnuF

.serodassecorp sortuo a sadanitsed snegasnem raivne ed e etnematomer ed sodatluser rebecer ,serodassecorp omoc iussop sortuo ed sadatucexe searepo sairnigiro ed snegasnem O

rebecer

sacisb

senuf

oacinumoc

.rodivres/etneilc olocotorp mu moc odroca ed ,setnerefid serodassecorp me uo rodassecorp omsem mu erbos sossecorp ertne oacinumoc a etimrep euq oacinumoc ed lenrekorciM o olelaraP lenrekorciM mu ed laicurc otnop O

.setnatsid serodivres rop sodicerefo soivres soa osseca o ritimrep a arienam ed adidnetse lenrekorciM adac ed oacinumoc

Operacionais 1.2 Estrutura e Funcionamento dos Sistemas


lenrekorciM

22

.odatluser mu mevloved e matucexe sa ,)ametsis ed sadamahc( soirusu sod seaticilos sa mebecer euq ,setnarepooc siaicneqes sossecorp ed oeloc amu omoc odazinagro OS O

socitlonoM

.sianoicarepo sametsis sod oaruturtse ed samrof siapicnirp sa sadatneserpa ores riuges A siam aruturtse sod a rartnocne ed ed avitatnet amrof me t A an ,odulove mt sad od .adairporpa sianoicarepo ecnamrofrep ohnepmesed

sametsis an

oaruturtse aicnulfni

.seacilpa ametsis

latnemadnuf

amu

lanoicarepo

o ,amrof atseD .odazilitu res ed selpmis siam o-odnanrot erawdrah o azilautriv euq ,erawdrah o e oacilpa ed samargorp so ertne sodautis ,setnerrocnoc sossecorp sosrevid rop odamrof ,amargorp mu lanoicarepo ametsis mU

sianoicarepO sametsiS sod aruturtsE

lanoicarepO ametsiS mu ed otnemanoicnuf od acitmeuqse osiV

32

ed ed

roiam

oremn

mu

ed

aicntsixe ed

etimrep amu

otnemges ed

ed o

oacifitnedi etnemataxe ed sanigp

omsinacem

mu e

airmem ed

anigp am U

ohnamat

iussop

ocitngam

robmat

anigp

.ocitngam

robmat

e airmem ed sanigp ertne onitsid amu atief iof e sanigp ed otiecnoc o odazilitu iof ametsis oN .airmem ed aicnreg alep levsnopser :1 levN

.sepurretni sad otnematart olep e oucexe me sossecorp so arap rodassecorp od oacola alep levsnopser :0 levN

:socigl sievn sies iussop ametsis O

.odazinagro iof ametsis o siauq son socigl sievn soirv son sodacoloc os e ametsis od setnenopmoc setnerefid sossecorp sod ed seartsba oremn sa matnemelpmi me sossecorp os setsE .siaicnqes sedadivita

otrec

mu

sadidivid

ametsis

od

sa sadot ,8691 me artskjiD rop odurtsnoc ,EHT lanoicarepo ametsis oN

.ametsis od otnemanoicnuf otiefrep o recelebatse arap ,oazinorcnis ed soticlpxe somsinacem ed edadissecen a etsixe

,adanimretedni lanoicarepo ametsis o mamrof euq sossecorp setnerefid sod oucexe ed sedadicolev sa omoC .setsed adanedrooc oa a e siaicneqes sossecorp so ertne oarepooc ad odatluser o ametsis od otnemanoicnuf O .ossecorp mu rop odatucexe .cte ,otnemanolacse o ,airmem ed aicnreg a ,ocirfirep ed revird adac ,oirusu ed amargorp adac ,missA .adinifed

meb onuf amu odnatucexe mu adac ,setnarepooc siaicnqes sossecorp ed otnujnoc mu ed amrof a bos odazinagro res edop lanoicarepo ametsis mU

ociuqrreiH

ocitlonoM lanoicarepO ametsiS

42

.ametsis od aruturtse a artsuli riuges a arugif A

.ametsis od rodarepo o atneserper :5 levN

.oirusu ed samargorp solep odamrof :4 levN

.ocirfirep mu moc samelborp ed osac on ,olpmexe rop ,oirssecen 2 o t sI levn .rodarepo od omoc racinumoc sa es arap levn )sodnamoc ets E ed rodaterpretni( osulcxe ed

sedadilanoicnuf

azilitu

.autm

somsinacem lat arap odnasu ,zev rop oasrevnoc acin amu etimrep ametsis O .acisf elosnoc amsem amu mahlitrapmoc siauq so ,ossecorp adac arap lautriv elosnoc amu atnemelpmi levn etsE .smaerts tuptuo solep e smaerts tupni solep sievsnopser sossecorp so es-martnocne levn etsen :3 levN

.ossecorp mu moc oasrevnoc amu recelebatse otne edop euq ,sodnamoc ed rodaterpretni oa odaivne eretcarac mu ,alcet amu atrepa rodarepo o odnauQ .oucexe me sossecorp so moc etsed oacinumoc a ritimrep arap ,rodarepo oa

ametsis od elosnoc ad oacola ad atart :snegasnem ed rodaterpretni :2 levN

.on uo lapicnirp airmem an tse anigp a es acidni levirav amU .airdnuces airmem an sanigp

52

siautriv saniuqM

.siamed sod etnednepedni etnematelpmoc arienam ed odatnemelpmi res edop laicneqes ossecorp adac euq

otsiv ,raludom otnemivlovnesed o etimrep e otnemanoicnuf od oerroc ad oacifirev a adauqeda siop ,adazilitu res ed etnasseretni ,setnednepedni sossecorp rop adamrof res ed otaf olep ,aciuqrreih oazinagro A

EHT lanoicarepo ametsis od oazinagrO

erawdraH

rodassecorp od oacolA

sotnemges ed rodalortnoC

snegasnem ed rodaterpretnI

S/E ed sossecorP

oirusu ed samargorP

rodarepO

62

o ratucexe a atlov ,odidep

oivres od odatluser

od

essop

ed

euq

,etneilc

oa etimsnart o e odatluser o rodivres od ebecer lenrekorciM O .oivres ovon mu ed oaticilos a rarepse a matlov e lenrekorciM oa odatluser o maivne ,matucexe o ,oivres mu ed oaticilos a mebecer lauq on ,onrete pool mu matucexe serodivres sO .serodivres soa ahnimacne so euq )lenrekorciM( OS oa soivres so maticilos )oacilpa ed samargorp( setneilC sO .lenrekorciM od amica ocigl levn mu me ,sodazilaicepse serodivres rop sodatnemelpmi os ametsis od soivres so sodoT .otnemanolacse od levn oxiab siam

ed senuf salep e ,socisb siam sotcepsa sues son airmem ed aicnreg alep ,sepurretni sad otnematart olep levsnopser )ominm( lenrekorciM mU .sodazilaicepse serodivres rop sodatnemelpmi os ametsis od soivres so lauq an ,rodivres/etneilc oledom on adaesab lenrekorciM oazinagro A lenrekorciM

.cte ,otnemanolacse o rezaf ,)... ,oeled ,oairc( siautriv saniuqm raicnereg ,rodatupmoc od erawdrah o raicnereg os senuf sauS .rodatupmoc od erawdrah on etnematerid

ador e ametsis od latnemadnuf etnenopmoc o margorP lortnoC O

.soirusu sortuo so moc rirefretni mes e aicnrefretni mes .cte ,sodad sues anezamra samargorp sues atucexe oirusu adaC .)093/MBI uo 073/MBI( lanoicarepo ametsis mu ed ataxe oalumis amu lautriv aniuqm atse odnes ,ametsis od oirusu adac arap lautriv aniuqm amu airc ,ocisf erawdrah

o aicnereg euq ,margorP lortnoC ed odamahc amargorp mu rop odalortnoc MV lanoicarepo ametsis adaC .siautriv saniuqm ed otiecnoc o azilitu euq lanoicarepo ametsis ed olpmexe mu MBI ad )enihcaM lautriV( MV O

.sadatucexe e laer aniuqm ad seurtsni arap sadizudart os lautriv aniuqm ad seurtsni sA .laer airmem ed an anigp amu ed a osseca mu me a )odizudart( O odaepam lautriv a euq edop .siaer aniuqm sosrucer airmem sosrucer

airmem moc

anigp

amu

osseca sairv

.laer

aniuqm

sonem ed

,siautriv

saniuqm moc

me

adanoicitrap ,amrof

res

edadicapac

ednarg

aniuqm

amu

atseD

arap sodaepam os euq siautriv sosrucer rop adamrof lautriv aniuqm amU

72

.xuniL od sievn siapicnirp ortauq so atneserpa oxiaba arugif A .erawdrah o e ametsis o ertne ecafretni a matnemelpmi sovitisopsid sod serodalortnoc sO amu .aniuqm oirusu ad oa osu o oirusu e oa odnitimrep lenrek ,erawdrah O .acifrg od oartsba a e

ecenrof

,ocitlonom

ecafretni

,serodalipmoc so ,sacetoilbib sa ,llehS o ,etnemacipit ,os ametsis od soivres sO .soirusu sod seacilpa sa matneserper oacilpA ed samargorp sO

.sovitisopsiD sod serodalortnoC e lenreK ,ametsiS od soivreS ,oacilpA ed samargorP :sievn sednarg ortauq rop odamrof xuniL lanoicarepo ametsis O xuniL lanoicarepo ametsis od oazinagrO :osac ed odutsE

.manitsed es siauq s seacilpa s sadauqeda ,sianoicidart seartsba ratnemelpmi medop serodivres

,olpmexe rop ,missA .sedadissecen saus s odauqeda otnujnocbus o etnemos azilitu ,oacilpa adac ,e erawdrah o etnematelpmoc aicnereg siauq sa moc ,levn oxiab ed savitimirp ed ocisb otnujnoc mu iussop lenrekoxe o ,amrof atseD .oacilpa adac a soirssecen sosrucer so recenrof ,etnemadauqeda ,eved lanoicarepo ametsis o ,seacilpa setnerefid ed satnitsid

sedadissecen s odived ,euq aidi A

.seacilpa sa sadot sadurtsnoc os

lauq a erbos erawdrah od latot oartsba amu recenrof eved omsem o euq ed oon a animile lenrekoxe me lanoicarepo ametsis mu ed oaruturtse A lenrekoxE

lenrekorciM oazinagrO

.rodivres ovon mu ed oaroprocni an etsisnoc euq ,soivres sovon ratnecserca es ed edadilicaf a e edadiraludom a os lenrekorciM oazinagro ad snegatnav sA .lenrekorciM oazinagro amu acifilpmexe riuges a arugif A .oacilpa ad ogidc

82

1.3 Tratamento de interrupes e Chamadas de Sistema


.sossecorp ertne oacinumoc ed somsinacem sosrevid so atnemelpmi euq ametsisbus ,)CPI( noitacinummoC ssecorP-retnI .5 .oacinumoc ed seder sa osseca o etimrep euq ,)teN( eder ed ecafretnI .4 .sianoicarepo sametsis sortuo moc sievtapmoc ,soviuqra ed sotamrof setnerefid mbmat atnemelpmI .sovitisopsid ed sopit setnerefid so sodot a mumoc ,emrofinu ecafretni amu airc euq ,ovitisopsid od aicndnepedni ed o odatnemelpmi otiecnoc mU .soviuqra ed ametsis o aicnereg euq )SFV( metsyS eliF lautriV O .3 .laer airmem a euq seroiam sossecorp ed oucexe a etimrep euq ,lautriv airmem atnemelpmi MM O .lapicnirp airmem an sossecorp soirv ed aicntsixe a etimrep euq ,)MM( airmem ed etnereg O .2 .odanoiceles ossecorp oa rodassecorp o ragertne e oucexe arap sossecorp ranoiceles rop levsnopser ,)dehcs( rodanolacsE .1 :sametsisbus ocnic rop odamrof xuniL od lenrek O xuniL lanoicarepO ametsiS sovitisopsid sod serodalortnoC xuniL od lenreK ametsis od soivreS soirusu ed samargorP

92

.)gniloop( odamargorP O/I

adaS e adartnE ed sopiT

.airmem an sodad ed oatnemivom mezaf euq seurtsni sa sadot sadasu res medop ,ocirfirep od rodalortnoc o e

rodassecorp o ertne oacinumoc a arap ,airmem an odaepam O/I o moC

.serodartsiger setsen sodad ed atircse arap adasu TUO .ocirfirep od rodalortnoc o moc oacinumoc an sodasu serodartsiger sod sodad ed arutiel arap adasu NI .)TUO e NI .xE( sodad ed atircse e arutiel ed sacifcepse seurtsni sairssecen os airmem ed otnemaeredne ed oapse od otnitsid otnemaeredne ed oapse o moC

.airmem ed oapse on soeredne odnapuco ed oapse ,airmem o uo an etnematerid etsed odaepam atief res edop otnemaeredne od rodalortnoc

,oapse

svarta

ocirfirep

o e rodassecorp o ertne seamrofni ed acort a e oacinumoc a e airmem ed otnemaeredne ed oapse od otnitsid ,odarapes otnemaeredne ed

oapse mu me sodaepam res medop adas e adartne ed sovitisopsid sO

.ocirfirep olep sodatucexe meres a sodnamoc

.)odapuco/ervil( ocirfirep

.arutiel ed oarepo amu ed setnatluser sodad so acoloc ocirfirep o e ocirfirep on sodavarg meres a sodad

:serodartsiger srt ritsixe meveD .serodartsiger ed svarta atief ocirfirep o moc PCU ad oacinumoc A .anorcnssa amrof ed marepo e ,sotnel

etnemamertxe os socirfirep so ,PCU a oaler mE

.adas e adartne ed

searepo san socirfirep so moc egaretni e seurtsni sa atucexe ,sodad e seurtsni ed acsub rezaf arap airmem a asseca euq )PCU( otnemassecorP ed lartneC edadinU amu rop odamrof oatupmoc ed ametsis mU

so

acoloc

rodassecorp

rodartsiger

etseN

:sodad

ed

rodartsigeR

od

odatse

erbos

seamrofni

mtnoC

:sutats

ed

rodartsigeR

so evercse rodassecorp o rodartsiger etseN :elortnoc ed rodartsigeR

03

.sossecorp

sortuo odnatucexe

acif rodassecorp o ,O/I ed searepo sa etnarud ,rodassecorp o AMD moC .lanoicarepO ametsiS olep adatart res euq ,opurretni amu adareg sodad ed aicnrefsnart ed oarepo ad onimrt oA .rodassecorp od onevretni

mes airmem a arap ocirfirep od etnematerid adirefsnart oamrofni A

)AMD( airmeM oteriD ossecA

.sossecorp sortuo ratucexe arap ervil acif rodassecorp o sodad ed aicnrefsnart ed oarepo a etnarud ,rodassecorp od oa ad etnednepedni ocirfirep od mu oa etsixE a omoC .opurretni ed a a e t n of adac ocifcepse onuf

otnematart a O

.adirroco

opurretni o ratucexe

etnednopserroc assap

atnemelpmi .opurretni

euq ed

otnemidecorp odidep mu

otne o

rodassecorp ,)adas uo

odnareg

rodassecorp

azilanis

adartne( sodad ed aicnrefsnart ed oarepo amu ed onimrt oa ,ocirfirep O

opurretni moc O/I

.)3 e 2 sahnil :gniloop( ocirfirep od sutats o odnatset odaidrepsed rodassecorp od opmet

od etrap roiam a euq odamargorp O/I od etneinevnocni ednarg O

1 otog otne O/I ed odidep ovon etsixe eS .6 airmem an adil oamrofni a revercsE ocirfirep od oamrofni reL otne arutiel ed odatucexe odnamoc eS .4 2 otog ydaer

TON sutatS eS .3 sutats reL .2

ocirfirep od

odnamoc mu ocirfirep oa aivne OS .1

:otnemanoicnuf ed .xE .UPC a epmorretni on ocirfirep od rodalortnoc O .)gniloop( O/I od odatse o ,ocirfirep o moc ecafretni an ,odnatset acif euq ,lanoicarepO ametsiS od elortnoc o bos sadazilaer os adas e adartne ed searepo sA

13

:setniuges sa os rodassecorp olep sadatucexe sea sa ,erawdrah ed opurretni amu erroco odnauQ erawdrah ed sepurretni ed otnematarT

.)oivres od oazilaer alep rarepse ratissecen etnaticilos ossecorp od osac on( odanoiceles ossecorp ovon mu uo etnaticilos

;)S/E ed osac on( ocirfirep oa ahnimacne o uo oirusu od

:erawtfos ed opurretni amu erroco odnauQ .)... ,part ,tni( laicepse ourtsni amu rop sadareg os sepurretni satsE erawtfos ed sepurretni ed otnematarT

.opurretni ed etnof etnednopserroc otnematart ed anitor ad oucexe a macovorp euq ,sepurretni ed aicnrroco egaer lanoicarepo ametsis O sepurretnI ed otnematarT

.orre ed oidnoc uo S/E ed oarepo ed lanif ed oazilanis :socirfirep solep sadareG ;oigler olep sadareG .cte ,oditimrep oapse od arof airmem a aicnrefer ,orez rop osivid :orre mu rop sadareG .)PART ,TNI .xe( siaicepse seurtsni ed osu o moc sadatnemelpmi :amargorp olep sadareG )a )b )d )c

:res medop sepurretni sA sepurretnI sad megirO

;ratucexe ed arap amargorp O

ossecorp olep odaticilos oivres o atucexe lanoicarepo ametsis O

ossecorp oa anroter elortnoc o ,oivres od oucexe ad lanif oA

;lauta ourtsni ad oucexe abaca rodassecorp O

;opurretni ed aicntsixe atset rodassecorp O

;lauta odatse avlas rodassecorp O

23

.ametsis ed adamahc amu me sossecorp sod sodatse ed oisnart ed ofarg o artsom riuges a arugif A .rador a otpa etnemavon etnatisiuqer ossecorp o anrot lanoicarepo ametsis o ,oviuqra od arutreba ed oarepo ad onimrt oA .oucexe arap odanoiceles ossecorp ovon mu e )oviuqra o osac on ,osrucer od arepse a( odaeuqolb ecenamrep aticilos a euq ossecorp o ,ametsis ed adamahc a atart lanoicarepo ametsis o euq me opmet o etnaruD .)nepo( ametsis ed adamahc amu azilitu oviuqra mu rirba arap ,olpmexe rop ,oucexe me ossecorp mU .levn oxiab ed seurtsni ed osu o moc sadatnemelpmi os etnemlareg e lanoicarepo ametsis o

e sodatucexe odnes samargorp so ertne ecafretni a os ametsis ed sadamahc sa ,otnatroP .ametsis ed sadamahc ed amrof a bos oacilpa ed samargorp soa sievsseca os lanoicarepo ametsis olep sodicerefo soivres sO

ametsiS ed sadamahC

;opurretni ad otnematart ed anitor

ad oeredne o moc amargorp ed rodatnoc agerrac rodassecorp O

;opurretni ad otnematart ed anitor an aemoc oucexe A

;atucexe opurretni ad otnematart ed anitor A

;odaruatser roiretna oucexe ed otxetnoc O

.adipmorretni anitor a arap anroter oucexe A

33

:soviuqra ed oalupinaM arap ametsis ed sadamahC

sossecorp ed elortnoc oa sadanoicaler ametsis ed sadamahC

.cte ,oacinumoc ,sovitisopsid ed oalupinam a ,soviuqra ed oalupinam a ,sossecorp ed elortnoc oa sadanoicaler

res medop ametsis ed sadamahc sA .sotpa ed alif an odiresni e rador arap otnorp odatse o arap assap ametsis ed adamahc ad onimrt oA .odaeuqolb odatse o arap assap e )adas e adartne ed oarepo amu uoticilos ,olpmexe rop( rodassecorp o edrep ametsis ed adamahc amu zaf odnauQ .odnador odatse o arap assap odanoiceles omsem o odnauQ .rador arap otnorp

tse ,ratucexe arap sotpa sossecorp ed alif amu arap oditembus odnauq ossecorp O .rador

me odiresni oucexe arap otnorp e odaeuqolb

,odnador :sodatse srt ertne oisnart merfos oucexe me sossecorp sO

;rairC

;ranimreT

;ratucexe ,ragerraC

;otneve razilanis ,otneve rop rarepsE

;opmet

ed megassap rarepsE

;airmem rarebil e racolA

.cte

;rateled ,rairC

;rahcef ,rirbA

;revercse ,reL

;ranoicisoP

.cte

43

.rodartsiger mu me odacoloc sortemrap ed aer ad oeredne o lauq an ,oulos artuo a adazilitu res edop ametsis ed sadamahc satse araP .sacuop otium os acitrp an euq o ,sievnopsid serodartsiger ed oremn o euq od roiam sortemrap ed oremn mu meussop euq ametsis ed sadamahc saleuqa arap adazilitu res edop on etnemos

oulos atsE .serodartsiger ed osu o moc atief ajes sortemrap ed megassap a euq levjesed ,ecnamrofrep ed setseuq roP .rodartsiger mu me odacoloc oeredne ojuc ,airmem ed ocolb mu ed svarta uo serodartsiger ed svarta otief res edop o t sI .lanoicarepo ametsis o arap sortemrap ed megassap

a etnatropmi otcepsa ortuO .oivres o ratucexe arap laicepse anitor amu ed adamahc ,olpmexe rop ,sadazilitu res matissecen seulos sartuo ,ourtsni ed opit etse meussop on euq serodassecorp mE .lanoicarepo ametsis

o arap oucexe ad elortnoc o erefsnart euq e otxetnoc ed acort arap adasu ,TNI ,laicepse ourtsni amu meussop letnI serodassecorp so ,olpmexe roP .etnetsixe erawdrah od edneped ametsis ed sadamahc sad oatnemelpmi A

ametsiS ed sadamahC sad oatnemelpmI

:sossecorp ertne oacinumoc setnerefer ametsis ed sadamahC

:sovitisopsid ed oalupinaM arap ametsis ed sadamahC

;rarebil ,racolA

;revercse ,reL

;aroh a racifidom ,rel :.g.e .ametsis od oamrofni ed onetunaM

.ctE

;oacinumoc ed sianac rateled ,rairC

;oamrofni rirefsnarT

.cte

53

.)daer( ametsis ed adamahc etnednopserroc otnemidecorp o acovni e otxetnoc od etnatser o avlas adamahc anitor A .sepurretni ed rotev od H08 oisop an artnocne es euq oeredne o retnuoc margorp oa odubirta e retnuoc margorp

o e ametsis od sutats ed arvalap a ahlip an acoloc tni ourtsni A

.lanoicarepo ametsis o arap elortnoc o assap ,tni laicepse ourtsni ad osu o moc ,e serodartsiger me sodibecer sortemrap so acoloc euq ,daer acetoilbib ed otnemidecorp od oucexe a arapsid ametsis ed adamahc atsE

.)02( sodil meres a sodad sod ohnamat o e )b&( sodanezamra res meved sodil sodad so lauq an airmem ed aer ad oeredne o ,)df( oviuqra od rodacifitnedi o sortemrap omoc

odnassap ,daer ametsis ed adamahc amu zaf oirusu o ,amica olpmexe oN

.C me otircse amargorp mu ed ritrap a ,daer ametsis ed adamahc ad oatnemelpmi ed olpmexe mu odatneserpa res riuges A

ametsis ed adamahc ed oatnemelpmi ed olpmexE

_read ( int fd, char *b, int l ) { move fd, regA; move b, regB move l, regC move READ, regD int 80H; } Biblioteca main() { read ( fd, &b, 20) ; } Programa do usurio

63

.xuniL on setnetsixe ametsis ed sadamahc samugla a sodaicossa soremn so matneserpa riuges a sahnil sA .ametsis ed sadamahc sad oremn o e e mon on mu lenrek iussop o mtnoc o arap h.dtsinu/msa/edulcni/rsu/ odassap ed euq ,siamed .h08 oviuqra O .XAE rodartsiger eugnitsid ourtsni a euq oremn

sad tni

ametsis

adamahc

adaC

alep

sadanoica

res medop euq ,ametsis ed sadamahc 002 ed siam atropus xuniL O

.h08 tni ourtsni ad osu o moc atief ,lenrek odom arap oirusu odom od ,otxetnoc ed acort a ,letnI serodassecorp soN ed od adamahc ossecorp .lenrek amu o od moc lanoicarepo olep so ametsis oa oivres o aticilos euq .ametsis oirusu

,lenrek

sadivlovnesed etnematerid

res

matissecen oditimrep

searepo oirusu

saN

soivres

rasseca

on

ed ossecorp mu A .ametsis od otnemaeredne ed oapse o e oirusu od otnemaeredne ed oapse o ertne onitsid zaf xuniL lanoicarepo ametsis O

xuniL on ametsis ed sadamahC

.lanoicarepo ametsis olep otief res euq o ,ametsis ed adamahc an odacoloc airmem ed oeredne o arap ocirfirep od sodad sod aicnrefsnart ad onimrt oa )ratucexe arap otnorp ratse(

odadroca res daer ametsis ed adamahc a uoutefe euq ossecorp O

.oucexe arap odanoiceles ossecorp ovon mu ,ametsis ed adamahc ad otnematart o atucexe euq anitor alep otief euq ,revird od otnemanoica o spA

#define #define #define #define #define #define #define #define #define #define #define

__NR_exit __NR_fork __NR_read __NR_write __NR_open __NR_close __NR_waitpid __NR_creat __NR_link __NR_unlink __NR_execve

1 2 3 4 5 6 7 8 9 10 11

73

.soirusu sortuo rop odasseca res assop oviuqra o euq

.ovitagen on orietni rolav mu ,oviuqra od rotircsed

:os

soviuqra ed oalupinam arap savitimirp samuglA

.soirterid e soviuqra me searepo ratucexe soirusu soa etimrep savitimirp ed otnujnoc mU :soviuqra ed oalupinam arap ametsis ed sadamahC

.ossecorp od etrom a racidni edop lanis O .sossecorp

.otnemugra omoc odassap ,levtucexe oviuqra mu ed emon olep odacifitnedi ,ossecorp ovon mu ed megami alep etnerroc

.odazilanis iap ossecorp o e tinI ossecorp olep

.etnemataidemi odnanroter ,odaeuqolb acif on ossecorp o e sodarebil os ohlif od sosrucer so ,)eibmuz odatse(ametsis ed adamahc atsed setna uonimret ohlif mu eS .enimret

.ametsis ed adamahc etniuges ourtsni a matucexe e ,olelarap me maunitnoc ohlif ossecorp o e rodairc ossecorp

:sossecorp ed elortnoc arap ametsis ed sadamahC

.soviuqra ed oalupinam a e sossecorp ed elortnoc oa setnerefer ,xuniL lanoicarepo ores ametsis A .cte on ,3 ametsis a ed ,2 sadamahc a krof siapicnirp ,1 onuf sa a sadatneserpa tixe ,missA

riuges

d a er

O .iap ossecorp od aipc amu euq ossecorp ovon mu airc :krof

ohlif mu euq ta etnerroc ossecorp od oucexe a ednepsus :tiaW

sodadreh os ,meritsixe es ,sohlif sO .etnerroc ossecorp o animret :tixE

ossecorp od megami a odniutitsbus ,amargorp mu atucexe :cexE

ed opurg uo ossecorp mu arap lanis mu raivne arap adasu :lliK

.otnemugra omoc odacificepse opmet olep ossecorp o ednepsus :peelS

on oviuqra od emon o odnetrevnoc ,odacificepse oviuqra o erba :nepO

odnitimrep e soieuqolb odnarebil ,oviuqra ed rotircsed mu ahcef :esolC

83

mu me ametsis ed sadamahc ed osu o acifilpmexe riuges a amargorp O

:os savitimirp siapicnirp sa soirterid me searepo ratucexe araP

.odibecer otnemugra

.odateled omsem o ,oviuqra oa odaicossa

.oviuqra omsem oa merefer

.epip on atircse arap odasu 1 adartne an odanroter o e epip on arutiel arap odasu rotev od 0 adartne an odanroter rotircse O .sossecorp ertne oacinumoc a ritimrep arap sodairc soviuqra

.b

oeredne od ritrap a sodirefsnart ,setyb l df oviuqra

on revercse atneT .)l( sotircse res oreved euq setyb ed edaditnauq

.b reffub on anezamra so e ,setyb l df oviuqra od rel atneT .)l( sodil res oreved euq setyb ed edaditnauq

e )b( reffub ,)df( oviuqra od rotircsed( sotnemugra srt ebecer :daeR

e )b( reffub ,)df( oviuqra od rotircsed( sotnemugra srt ebecer :etirW

.oviuqra ovon mu airc :taerC

ed serotircsed ed rap mu sotnemele siod ed rotev mu me anroter :epiP

es semon siod sO .etnetsixe j oviuqra mu arap ominnis mu airc :kniL

emon omitl od es-odnatarT .oviuqra ed emon mu animile :knilnU

olep adacidni oisop an oviuqra od etnerroc etyb o acoloc :keesL

.otnemugra olep odacificepse emon o moc oirterid ovon mu airc :ridkm

.odacificepse oirterid o evomer :ridmr

.odacificepse oirterid od odetnoc o atsil :sl

soviuqra soa osseca ed sotierid so racifidom arap adasu :domhc

# Para mont-lo digite as syscall.s -o syscall.o # Para gerar o executvel digite ld -s syscall.o
.relbmessa me otircse amargorp .sodacificepse

# Exemplo de programa que executa chamadas de Sistema no Linux

-o syscall

.data O_RDONLY STDOUT SYS_EXIT SYS_READ SYS_WRITE SYS_OPEN SYS_FORK len file: msg: STDOUT .comm .text .global _start: # Al mov mov mov mov int _start = = = = = = = = 0 1 1 3 4 5 2 13

# Seo de dados inicializados

.string .string

"Teste.txt\0" # Arquivo a ser lido "Alo mundo!\0" # Mensagem a ser escrita em

buf, 512

# buffer com 512 Bytes # Seo de cdigo

mundo $len, %edx $msg, %ecx $STDOUT, %ebx $SYS_WRITE, %eax $0x80

# # # # #

Tamanho da mensagem apontador para o buffer Arquivo de sada: STDOUT Nmero da chamada de sistema (write) Chamada do kernel

# int open (const char *pathname, int flags, mode_t mode) mov $O_RDONLY, %edx # Abertura do arquivo para leitura mov $0 , %ecx # Flag para abertura (0) mov $file, %ebx # Nome do arquivo a ser aberto mov $SYS_OPEN, %eax # Nmero da chamada de sistema (open) int $0x80 # Chamada do kernel # int read(int fd, void *buf, size_t count) mov $40, %edx # Quantidade de bytes a serem lidos mov $buf, %ecx # apontador para o buffer mov %eax, %ebx # Descritor do arquivo a ser lido mov $SYS_READ, %eax # Nmero da chamada de sistema (read) int $0x80 # Chamada do kernel # int write(int fd, const void *buf, size_t count) mov $40, %edx # Tamanho da mensagem mov $buf, %ecx # apontador para o buffer mov $STDOUT, %ebx # Arquivo de sada: STDOUT mov $SYS_WRITE, %eax # Nmero da chamada de sistema (write) int $0x80 # Chamada do kernel # int _fork() mov $SYS_FORK, %eax int $0x80 # Al mov mov mov mov int mundo $len, %edx $msg, %ecx $STDOUT, %ebx $SYS_WRITE, %eax $0x80

# No. da chamada de sistema (sys_fork) # Chamada do kernel

# # # # #

Tamanho da mensagem apontador para o buffer Arquivo de sada: STDOUT Nmero da chamada de sistema (write) Chamada do kernel

93

04

.ossecorp mu ed oairc an lanoicarepo ametsis olep sodatucexe sossap so sodot avercseD .otxetnoc ed acort arap evres euq )TNI( laicepse ourtsni amu etsixe euq e )... ,2R ,1R ,0R( serodartsiger sod svarta OS o arap sodassap meved sortemrap so euq odnebas ossecorp o euq moc ,sodnuges t rop odaeuqolb euqif atucexe a euq zaf euq ,)t(peels acetoilbib ed anitor a avercsE .5 .6

.euqifitsuJ ?lareg osu ed odamargorpitlum lanoicarepo ametsis mu me ol-mrofsnart arap opit etsed ametsis mu me sadatnecserca res meved sedadilanoicnuf euQ .lareg osu ed odamargorponom .4

lanoicarepo ametsis mu me sairssecen sedadilanoicnuf sa avercseD .lenrekorciM oledom on odaesab lanoicarepo ametsis mu ed otnemanoicnuf o avercseD .lenrekorciM e acitlonoM seazinagro sa erapmoC .oigler ed opurretni amu ed otnematart on lanoicarepo ametsis olep odatucexe otnemidecorp od ogidc-oduesp o avercsE

.3 .2

.1

.oucexe a razilanif arap sossecorp siod solep adatucexe ,tixe e odnum lA gnirts o ordap adas an evercse

euq ,sossecorp siod solep adatucexe ,etirw ,ossecorp ovon mu airc euq krof ,daer avitimirp alep odil odetnoc o )elosnoc( ordap adas an evercse euq etirw , fub me anezamra o e txt.etset oviuqra od seretcarac oviuqra o erba euq

04 ta ed gnirts mu l euq daer

,arutiel arap

t x t . e t s et

nepo ,)elosnoc( ordap adas an

odnum lA

gnirts o evercse euq ,etirw

:ametsis ed sadamahc etes rop odamrof amica odatneserpa amargorp O

Exerccios
# void _exit(int status) mov $0, %ebx # Cdigo do exit mov $SYS_EXIT, %eax # Nmero da chamada de sistema (exit) int $0x80 # Chamada do kernel

14

.otxetnoc ed acort arap adazilitu H08

tni ourtsni amu etsixe euq e 0R rodartsiger on adacoloc res


eved OS olep odatucexe res a oivres od oacifitnedi a euq ,)... ,2R ,1R( serodartsiger me sadacoloc res meved oivres od oazilaer a arap sairssecen )sortemrap( seamrofni sa euq odnebas ,

)(tixe e )galf tni (tiaw ametsis ed sadamahc


)a

sa matnemelpmi euq acetoilbib ed otnemidecorp so avercsE

:)tiaw avitimirp alep( odaeuqolb revitse omsem o es iap ossecorp o adroca e atucexe a euq ossecorp o animret

)(tixe ametsis

ed adamahc a euq e )menimret sohlif so sodot euq ta odaeuqolb acif ossecorp o 1 a laugi rof ortemrap omoc odassap otnemugra o es( enimret ohlif ossecorp mu euq ta atucexe a euq ossecorp o aieuqolb

)galf tni (tiaw ametsis ed adamahc a euq odnebaS


?euqroP ?sodamargorponom sametsis me

.11

airssecen alebat atsE .sodamargorpitlum sametsis

me sossecorp

ed serotircsed ed alebat ad aicntsixe ad edadissecen a euqifitsuJ .01 .serodartsiger uo sievirav res medop

2po e 1po edno 2po ,1po vom oarepo amu ed

aicntsixe a atnoc me eveL .rotircsed ortsiger ues me ovlas ossecorp od otxetnoc o euq evresbo e )sossecorp ed rotircsed( sossecorp so erbos seamrofni sa saditnam os lauq an sodad ed aruturtse a anifeD .)CP( seurtsni ed rodatnopa mu e )CA( rodalumuca mu ,)PS( retnioP kcatS rodartsiger mu ,otnemacolsed e esab etnemavitcepser ,)ezisM e esabM( airmem ed aicnreg arap sodazilitu serodartsiger siod ,)1R e 0R( lareg osu ed serodartsiger siod iussop ametsis o euq eredisnoC .otxetnoc ed oaruatser e otnemavlas

rezaf ,etnemavitcepser ,arap lanoicarepo ametsis olep sodatucexe ,

)(txetnoc_erotser e )(txetnoC_evas sotnemidecorp so avercsE


.ocsid od opurretni amu ed otnematart on lanoicarepo

.9

ametsis olep odatucexe otnemidecorp od ogidc-oduesp o avercsE .oisnart ad rodasuac otneve o odnacidni ,oisnart ed ofarg o aaf e oucexe aus a etnarud emussa ossecorp mu euq sodatse so etneserpA

.8

.7

24

.soivres setsed oazilaer an lanoicarepo ametsis olep sodatucexe sotnemidecorp so avercseD )b

Bibliografia

34

,odatse ed seisnart sa ,sossecorp sod sodatse so ,setnerrocnoc sossecorp ed otiecnoc o atneserpA .setnerrocnoc sossecorp sod odutse oa odacided olutpac etsE arap .sodasep e sevel omoc sodacifissalc res medop e ,oucexe od airmem an sodagerrac samargorp os sossecorP

rodatupmoc

Concorrentes 2. Processos

44

.sossecorp sod sodatse ed oisnart a artsuli riuges a arugif A .adas e adartne ed oarepo amu ed arepse a tse ,olpmexe rop ,rador arap oidnoc amugla ed arepse a tse es dekcolb odatse mu me tse e ,rodassecorp olep odnarepse tse e odatucexe res arap seidnoc iussop es ydaer odatse mu me ts E .rodassecorp olep sadatucexe odnes otse

seurtsni saus es gninnur odatse on tse )eveL uo odaseP( ossecorp mU

;retnuoc

;laicneqes ogidc mu ador mu adaC

:os sevel sossecorp sod sacitsretcarac siapicnirp sA .odasep ossecorp mu ed oucexe

an omsilelarap ritimrep arap sodairc os )sdaerht( sevel sossecorP .oucexe arap ocsid od sodagerrac os etnemlamron e laicneqes ogidc mu matucexe ,)C amargorp mu ed

niam

.xe( oucexe aus a aemoc euq laicini daerht

amu meussoP .sianoicidart sossecorp so os sodasep sossecorp sO

.sevel sossecorP e sodasep sossecorP :sopit siod me sossecorp so racifissalc es-edoP .oucexe arap airmem an odagerrac ed )otejbo ogidc( odalipmoc me amargorp o e ,C olpmexe mU rop ,oamargorp olep

megaugnil

amu

odamargorp

omtirogla

.rodassecorp

odatucexe odnes omtirogla mu a setnerefer seurtsni sad oucexe alep e erawdrah ed sosrucer solep adamrof ,atartsba edaditne amu ossecorp mU .somtirogla matneserper euq seurtsni matucexe serodassecorp sO

oacificepse ed somsinacem e setnerrocnoc sossecorp erbos searepo sa

2.1 Processos Concorrentes

.aicnrrocnoc ed

margorp oirprp ues o e oucexe ed ahlip airprp aus meussoP

;rodassecorp od osu o mahlitrapmoC

;sohlif )sdaerht( sossecorp rairc medoP

.)siabolg sodad( otnemaeredne ed oapse omsem o mahlitrapmoC

54

)1P( ; 51 + x = x )0P( ; 01 + x = x

searepo ed aicnqes an = x es

,5

,olpmexe roP .sadazilaer merof atircse ed searepo sa euq me medro ,sossecorp siod solep etnemaenatlumis .etnatropmi satief os searepo

ad redneped ri osserpmi rolav o adacifidom r of x levirav a eS

satse euq me medro a ,atlusnoc ed e oacifidom ed searepo matucexe siod lauq a erbos ,x levirav amu mehlitrapmoc sossecorp srt euq odnopuS

.rodassecorp od etnemavon arepse a ,ydaer odatse o arap assap e rodassecorp o edrep ossecorp o ,animret opmet etse odnauQ .oucexe me sossecorp soa rodassecorp od opmet ed s a i t af meubirta

euq sametsis me erroco ydaer arap gninnur ed oisnart A .)adas e adartne ed oarepO .xe( otneve mu ed aicnrroco alep rarepse atissecen odnauq dekcolb arap gninnur odatse mu ed assap e ,odnarepse avatse lauq olep otneve o erroco odnauq ydaer arap dekcolb odatse mu ed assaP .sadatucexe res a maemoc gninnur seurtsni odatse o saus arap e rodassecorp odatse o ahnag assap ,odanoiceles ossecorp mU

odnauq

2.2 Condies de Concorrncia


ydaer od

64

.acitsnimreted Q e P ed oucexe a

otne ,aizav )Q(W

e ,aizav )Q(R

e ,aizav )Q(W

es

,Q e P

sossecorp siod odnaredisnoC

nietsnreB ed seidnoc sA otnujnoc od

.) P( W ,B ed

etirw

otnujnoc od e )B(R ,B ed

etrap zaf x euq evresbO .}y ,x{ = )B(W ,}w ,x ,v ,u{ = )B(R otne

;w * x = y ;v + u = x

:rof B es ,olpmexe .B ed searepo sa sadot ed

etirw

sotnujnoc sod oinu a ,)B(W ,B ed

otnujnoc o ,etnemralimiS .B ed searepo sa sadot ed oinu a ,)B(R ,B oacilpa amu ed

daer

sotnujnoc sod

daer

otnujnoc O .A rop satircse e A rop

)sadatlusnoc( sadil sievirav sad otnujnoc o etnemavitcepser os A oacilpa a mu ed

etirw

otnujnoc o e

daer

otnujnoc O .ocitsnimreted amargorp mu

es racifirev arap sadasu os ]66 nietsnreB[nietsnreB ed seidnoc sA .odanimretedni otnatrop odnes ,sodnamoc sod oucexe ed medro ad redneped ri osserpmi res euq x levirav ad rolav o ,missA .51 res osserpmi rolav o ,oiubirta ariemirp a spa odatucexe rof tnirp odnamoc o es ,odal ortuo roP .03 rolav o rimirpmi ri 2P ossecorp o

)2 P(

; x

a)

,Q ed etirw otnujnoc o moc )P(W

,P ed etirw otnujnoc od ocesretni A

b)

,Q ed daer otnujnoc o moc )P(W

,P ed etirw otnujnoc od ocesretni A

c)
:os

,Q ed etirw otnujnoc o moc )P(R

,P ed daer otnujnoc od ocesretni A

daer

ro P

etirw

tnirp

74

:etniuges o laicneqes amargorp etsed aicndecerp ed ofarg O

)5s( ; c + e = h )4s( ; 5 + d = e )3s( ;g + f = d ) 2 s( ; b + a = c ) 1 s( ; 3 + z = b )0s( ;y + x = a

:laicneqes amargorp etniuges o odnaredisnoC .)setnerefid sedadiralunarg( alelarap aniuqm amu rop adatucexe

res a ,ourtsni acin amu ratneserper edop uo ,lanoicarepo ametsis o arap ossecorp mu ratneserper edop aicndecerp ed ofarg mu me n mU

.raemoc assop j edadivita a euq setna j n sn mu arap i n so edno

ranimret eved i edadivita

a euq acidni

mu ed ocra mu edno e siaicneqes sedadivita matneserper ,odigirid ofarg mu aicndecerp ed ofarg mU

ocilcca

aicndecerp ed sofarG

84

aicnrrocnoc racificepse arap megaugnil ed seaton sariemirp sa m a r of

nioj/krof

savitimirp

sA

]3691 ,yawnoC ;6691 ,nroH naV dna sinneD[ nioj e krof seurtsnoC

ed

oazinorcnis

ed

somsinacem

o e omsilelarap od osserpxe ed somsinacem sodatneserpa ores riuges A .amargorp od oucexe an omsinimreted es-retbo a arienam ed seucexe sa razinorcnis omoc e ofarg mu ed omsilelarap o rasserpxe omoc :aicndecerp ed sofarg sod esilna alep matlasser siatnemadnuf sotcepsa sioD

etnemos 5s .3s ed onimrt od sioped etnemos 4s ed oucexe a ,1s e 0s ed onimrt od sioped raemoc edop etnemos 2s ed oucexe A .olelarap me sodatucexe res medop 3s e 1s ,0s sodnamoc so ,aicndecerp ed ofarg etseN

amica laicneqes amargorp o arap sossecorp ed ofarG

4s

3s

2.3 Especificao de Concorrncia


.sossecorp soa odacided res etniuges olutpac .4s e 2s ed lanif o spa odatucexe res edop 5s 2s 1s 0s

94

moc aditbo res edop

krof odnamoc o moc alelarap oucexe A

; 2 / e = f ; 4 = e :2S

; 2 + c = d ; 3 = c

:1S

; 7 + a = b ; 5 = a :0S

:sodnamoc so odnaredisnoC .odairc ossecorp o moc olelarap me aunitnoc euq ,0P ossecorp od a e 1P ossecorp olep adatucexe res euq amU .saud me oatupmoc a odnidivid ,1P ossecorp o odnairc ,krof oarepo a atucexe 0P ossecorp o ,amica arugif aN

.krof oarepo a artsuli riuges a arugif A .olelarap me oucexe a maunitnoc


odairc ossecorp od o e

krof

adamahc ed

uoutefe o

euq

ossecorp

.rodairc ovon O

ossecorp .

otnemaeredne

oapse

ahlitrapmoc

ossecorp

lebal o moc ourtsni an oucexe a aemoc euq ossecorp ovon mu aicini

v krof

avitimirp A

S0, que inicialmente executa a operao fork L0; que cria um novo processo que comear sua execuo no comando com o label L0 e que executar o comando S1. Aps a execuo desta primitiva, o programa possui dois processos que executam em paralelo. O processo inicial, que executa o comando S0, continua a execuo no comando seguinte e executa uma nova operao fork para criar um novo processo, que inicia no label L1 e executar o comando S2. Existir, portanto, dependendo da velocidade de execuo, trs processos em execuo paralela, S1, S2 e S3. A figura a seguir ilustra o fluxo de execuo do programa acima.

05

; m i F ot o g

; m i F ot o g

A execuo comea com o processo que executar o comando

; 1 L k r of

; 0L krof ; tixe ; 1S ; 2S ; 0S :miF :0L :1L

Existem situaes nas quais um processo deve continuar somente aps um conjunto de processos terem terminado. Por exemplo, no programa apresentado acima, se for necessria a execuo de um comando S3, que soma todas as variveis calculadas por S0, S1 e S2, o mesmo somente poder ser executado ao final da execuo destes comandos. A instruo
rdda ,retnuoc nioj

oirrtnoc osac

rolav o eS .orez moc arapmoc o e

seucexe

15

sairv

,rdda

oeredne od ritrap a atucexe

anibmoc

krof ed osu moc olelarap amargorP

1S

nioj

miF

0L krof

0S

retnuoc

oarepo

2S

atnemerced ,yawnoC rop adinifed

1L

0S a krof ossecorp o ,orez a laugi rof , a m r of atse D 0S .animret

25

.latot

amos a aluclac ,amos a ranimret a ossecorp omitl o e B rotev

od sotnemele sod ortuo ,A rotev od sotnemele sod amos a aluclac ossecorp mU .C megaugnil-oduesp sotnemele sod amu me odamargorp tse O . e ,B e A ,serotev

siod ed

amos

a aluclac amargorp

nioj/krof

seurtsnoc

sad osu o artsuli riuges a olpmexe O euq

.atucexe a euq ossecorp o irtsed

,tiuq

oarepo amu moc otief otsI .0 ed etnerefid

tnuoc

levirav ad

rolav o odnauq oucexe aus animret ossecorp mu ,

nioj

ourtsnoc aN

.levsividni arienam ed sadatucexe res meved etset o zaf euq a e levirav a matnemerced euq searepo sa euq acifingis otsI .acimta res reved amsem a ,

nioj

oarepo a etnemetnerrocnoc ramahc medop sossecorp soirv omoC

nioj ourtsnoC

tiuq

0 =!

retnuoc

rdda ot og

0 =

; 1- retnuoc = retnuoc

rdda ,retnuoc( nioj

.)oxiaba arugif( manimret ,orez euq roiam so ,aunitnoc

retnuoc ed rolav o omoc ,siamed


.nioj mu ratisiuqer eved

nioj

o ratucexe a ossecorp omitl O

sossecorp ed opurg od etnapicitrap ossecorp adaC .amu me setnerrocnoc

35

krof

avitimirp

ad

oairav

amu

atnemelpmi

xuniL

lanoicarepo

ametsis

O .sossecorp ed acimnid oairc ed omsinacem etnelecxe mu matneserper adanilpicsid amrof ed sodasu es ,mroP .amargorp on sodairc res ori

euq sossecorp so rebas arap sodatucexe ores sotnemidecorp siauq rebas oirssecen siop ,sodidnetne res ed siecfid manrot es amrof atsed sotircse samargorP .sianoicidnoc sodnamoc ed e spool ed etrap rezaf odnedop

,ogidc ed ohcert reuqlauq me recerapa medop

nioj/krof

searepo sA

.serotev siod sod sotnemele sod latot amos a raluclac ,etnemetneqesnoc ,ossecorp ortuo O .animret o euq ,

tiuq

oarepo a ,otnatrop ,odnatucexe ,MIF olutr

od ritrap a ratucexe on omsem o e orez euq roiam res tnuoc ed rolav o

nioj

oarepo a ratucexe euq ossecorp oriemirp o araP .A rotev od sotnemele

so amos

krof

adamahc a uoutefe euq ossecorp O .B rotev od amos a ,0L

lebal od ritrap a atucexe euq ,ossecorp mu odairc amica amargorp oN

} main() { L2: somatotal = soma0 + soma1 ; L1: join count, L2 ; L0: for (j=0; j<N; j++) for (i=0; i<N; i++){ fork L0 ; int A[1, N], B[1, N] ; int i, j ; int N = 100 ; int soma0=0, soma1=0, somatotal=0 ; int FIM, L0, L1, count = 2 ; go to L1 ; } soma0 = soma0 + A[i] ; Soma1 = soma1 + B[j] ;

45

xinU on krof moc amargorp ed olpmexE

.enimret )tiaw oarepo a uotucexe euq olep odairc( ohlif ossecorp mu euq ta atucexe a euq ossecorp o aieuqolb

;fi odnamoc o moc sossecorp

;odairc ohlif ossecorp

;ossecorp ortuo od sievirav s oaler me setnednepedni os euq ,sievirav sa sadot ed

;ogidc omsem

:setniuges sa os xuniL on

krof od sacitsretcarac sA
;

) ( k r of = di

:amrof etniuges a iussop xuniL ametsis on krof ourtsnoc A .etnemroiretna adatneserpa

o matucexe siod so e adamahc a atucexe euq ossecorp o acilpuD

aipc moc ,otnemaeredne ed oapse oirprp ues met ossecorp adaC

;ametsis ed adamahc etniuges ourtsni a matucexe sobmA

od rodacifitnedi o ,iap ossecorp on ,mtnoc ,adamahc ad onroter on ,

di

;orez res

di levirav ad rolav o ohlif ossecorp o araP

solep odatucexe res euq ogidc ed ohcert o ranoiceles es-edoP

euq ,))(tiaw moc atief oazinorcnis a( nioj odnamoc o etsixe oN

#include <signal.h> #include <sys/types.h> #include <stdio.h>

55

sossecorp srt moc ofarG

2P

1P

0P

riuges a ofarg O .ranimret mbmat euq ,tiaw on odaeuqolb avatse euq ,iap ossecorp o raeuqolbsed onimrt ues O .animret riuges a e atucexe ele ,oslaf

ftnirp

fi

od etset o ohlif ossecorp o arap omoC .enimret ohlif

ossecorp o euq ta aieuqolb o euq os e .orez oriedadrev

,)0( tiaw

ftnirp

sodnamoc so sodatucexe

)0 =! di( fi

etset o iap ossecorp o arap ,amrof atseD

di

levirav ad rolav o ohlif ossecorp o arap e ,ametsis on acifitnedi

o euq ,ohlif ossecorp od oairc ed oremn o o ,adamahc a uotucexe euq o

di

levirav an odanroter rolav

ad adamahc a moc ossecorp mu odairc ,C me otircse ,amica amargorp oN

else

if (id != 0) {

id = fork () ;

int id ;

int main() {

printf(Eu sou o filho\n)

wait(0) ;

printf(Eu sou o pai\n) ;

,iap ossecorp o araP

)( krof = di

avitimirp

65

riuges a sossecorp ed ofarg O

.).cte ,airmem( ossecorp oa sodacola sosrucer so odnarebil ,atucexe a euq ossecorp o animret euq

,)( tixe avitimirp a adazilitu amica amargorp oN

:amrof etniuges ad xuniL on

res edop ,1P ed onimrt o spa etnemos ratucexe 2P euq e ranimret 0P euq sioped atucexe 1P euq odnacidni ,setnerefid sossecorp srt odnatneserper

int main () { #include <signal.h> #include <sys/types.h> #include <stdio.h>

int id0, id1 ; // cdigo de P0 id0 = fork () ; if (id0 != 0) exit (0) ; // P0 termina else{ //cdigo de P1 id1 = fork () ; if (id1 != 0) exit (0) ; //P1 termina else { // cdigo de P2 } } }

krof moc odamargorp

#include <stdio.h> #include <sys/types.h> #include <signal.h>

int main () { int id0, id1, id2 ; // cdigo de P0 id0 = fork () ; if (id0 != 0) { id1 = fork () ; if (id1 != 0) exit (0) ; // P0 termina else { // cdigo de P2 } } else{ //cdigo de P1 id2 = fork () ; if (id2 != 0) exit (0) ; //P1 termina else { // cdigo de P3 } } }
dnEoC nigeBoC seurtsnoC

75

odamargorp res edop xuniL on

sossecorp ortauq moc sossecorp ed ofarG

2P

krof moc

0P ,sossecorp ortauq odnatneserper :riuges a odatneserpa omoc 3P 1P

85

.dneoc/nigeboc ourtsnoc a artsuli riuges a arugif A .etnemetnerrocnoc sodatucexe os dneoc o e nigeboc o ertne sossecorp so sodot ,missA .oucexe a aemocer ,nigeboc o uotucexe euq o ,iap ossecorp o e ,odatucexe dneoc o ,meranimret sossecorp

setse sodot odnauQ .dne/nigeb rop sodatimiled os sotsopmoc sodnamoC .sotsopmoc uo selpmis res medop dneoc/nigeboc o ertne sodnamoc

so ,loglA megaugnil an odaesaB .dneoc o e nigeboc o ertne sodnamoc sod mu adac ratucexe arap ossecorp mu odairc odatucexe nigeboc o odnauQ

;dneoc

;nS

..

;2S

;1S

nigeboc

:etniuges a lareg amrof A .adazilitu res ed licf siam e ,krof ourtsnoc a adarapmoc es ,levn otla siam ed ourtsnoc amu .8691 artskjiD rop adairc iof ,dnEraP nigeBraP me

adamahc mbmat ,ourtsnoc atsE

95

dneoC

dne

; )h ,g ( d

; )s ,r( c

nigeb

; )j ,i( b

; )z , y ,x( a

nigeboC

riuges a olpmexe O

dneoc/nigeboc ourtsnoC

dneoc

nP

2P

1P

nigeboc

06

.g oviuqra mu arap f oviuqra mu ed aipc a rezaf arap etnerrocnoc odnamoc azilitu riuges a amargorp O

0P

dneoC

nigeboC

0P

odnamoc etsed oucexe a artsuli riuges a arugif A

.d e c otnemidecorp

sod sadamahc sa etnemlaicneqes sadatucexe ores ,otsopmoc odnamoc oN .otsopmoc odnamoc o moc olelarap me sodatucexe ores selpmis sodnamoc sO .)h ,g ( d e rop odatimiled )s ,r( c otnemidecorp ed sadamahc sa odnetnoc ,dne/nigeb ,otsopmoc odnamoc mu rop e )j ,i( b otnemidecorp od e

) z , y , x( a

otnemidecorp od adamahc a ,selpmis sodnamoc siod rop odamrof

a(x, y, z)
.etnerrocnoc

b(i, j)

c (r, s) d (g, h)

16

:seautis srt me animret ossecorp mU

sossecorp ed onimrT

.)... ,sotreba soviuqra( sievirav sad otnujnocbus mu mahlitrapmoc ,

krof

od ritrap a ,e iap ossecorp od aipc amu ohlif ossecorp o .menimret so sodot

krof

odnamoc od xuniL oatnemelpmi an ,sodad soa oaler moC ourtsnoc an sodairc setnerrocnoc sossecorp

dneoc/nigeboc
euq ta

dneoc

on odaeuqolb acif iap ossecorp o

dneoc/nigeboc ,krof

moC .ohlif

ossecorp o moc etnemetnerrocnoc atucexe iap ossecorp o .etnemroiretna sadatneserpa ,

avitimirp aN

krof

dneoc/nigeboc

opit od os savitimirp sa

sossecorp ed oairc a araP .sossecorp ed oazilanis e oieuqolb ,oiurtsed ,oairc matimrep euq savitimirp recerefo eved lanoicarepo ametsis O

sossecorp

ed oalupinam arap savitimirP

.etelpmoc es aipc a euq ta meteper es searepo satsE .f oviuqra od setyb i somixrp sod arutiel a zaf ossecorp ortuo mu on setyb
i

,g oviuqra oN

so

avarg

ossecorp

mu

otnauqne

,amica

amargorp

} int main() { int i, j, k ; char buffer0[4096], buffer1[4096] ; FILE f, g ; while (i > 0) { i = read (f, &buffer0, 4096) ; coend ; cobegin for (j=0; j<i; j++) buffer1[j] = buffer0[j] ; i = read (f, &buffer0, 4096) ; k = write (g, &buffer1, i) ; }

26

lanoicarepo ametsis on

llik avitimirp ad osu o artsuli riuges a olpmexe O

.oairc ed oarepo an anroter euq ,ohlif od edaditnedi a recehnoc atissecen iap o ,ratam redop arap

.O.S olep sodarebil os sosrucer sueS .etnemlamron animret atucexe a euq ossecorp O

:os sossecorp ed onimrt o matnemelpmi euq savitimirp sA

.)odanimret res atissecen e onrete pool mu me tse ossecorp mu .xe( siaicepse

;)setimil sod arof rotev mu ed oeredne .xe( odnamoc omitl ues o ratucexe

;odnamoc omitl ues ed oucexe a abaca odnauQ

ed setna rabaca edop ossecorp mu siaicepse saicntsnucric mE

savitimirp moc sossecorp sortuo ed etrom a rasuac edop ossecorp mU

)( tixe

)di( llik ,)di( troba

;ranimret ossecorp od oacifitnedi a di

;di ossecorp od iap olep sadamahc os

llik e troba

if (id != 0) {

id = fork () ;

int id ;

int main() {

#include <signal.h>

#include <sys/types.h>

#include <stdio.h>

} kill (id, SIGKILL) ; sleep(5) ; printf(Eu sou o pai\n) ;


.xuniL

36

arap etnemos ,daerht amu arap etsixe on paws ed oarepo A .oucexe arap odagerrac res assop amargorp ovon mu euq ritimrep e airmem

rarebil arap ocsid me adavarg e lapicnirp airmem ad adariter res ,oucexe aus a etnarud ,edop on daerht amu , otsi , oN .dekcolb ,gninnur ,ydaer deppaws odatse etsixe

sodatse so ertne oisnart merfos sdaerht sA

.rodamargorp olep sodazilitu res meved oazinorcnis ed somsinacem ,sodad sod aicnreoc a retnam araP .odasep ossecorp omsem od sdaerht sartuo sa levnopsid

os daerht amu rop sotreba soviuqra so e anadum atse mebecrep sadot ,odahlitrapmoc rolav mu aretla daerht amu odnauq ,otnatroP .mecnetrep lauq

oa odasep ossecorp od )siabolg sodad( otnemaeredne ed oapse omsem o od mahlitrapmoc osu o e sohlif )sdaerht( sossecorp m a r of rairc medop ,rodassecorp ossecorp(

mahitrapmoc

,sadinifed

lauq

on

)odasep

oacilpa ed amargorp on odinifed ,laicneqes ogidc mu ador amu adac

,retnuoc margorp

oirprp ues o e oucexe ed ahlip airprp aus meussop

sdaerht sA .sotnop setse merof sotnauq oucexe ed sdaerht satnat iussop oucexe ed sotnop solpitlm moc amargorp mU mu me omsilelarap ritimrep arap sodinifed ,sevel .oacilpa ed amargorp sossecorp os sdaerhT

.iap ossecorp olep adatucexe , a moc odanimile )

)1(elihw(

onrete pool mu me avatse euq ,ohlif ossecorp

o ,opmet etse odirrocsnarT .sodnuges ocnic etnarud aieuqolb o euq , avitimirp a atucexe ,

krof

o spa ,iap ossecorp o amica amargorp oN

2.4 Processos leves (Threads)


)LLIKGIS ,di( llik avitimirp )5(peels
}

}
else{ while(1) ; printf(Eu sou o filho\n)

46

oirusu ed levn a sdaerht ed snegatnavsed e snegatnaV

.odasep ossecorp od odatse od etnednepedni sdaerht sad odatse O

;gninnur odatse on adnia ratse odnador daerht a ,sdaerht ed acetoilbib a arap ,otnatne oN .odaeuqolb res odasep ossecorp odot ,ametsis ed adamahc amu zaf daerht amu odnauQ

:os oirusu levn a sdaerht ed sacetoilbib ,lenrek sad odom sacitsretcarac od soiglivirp siapicnirp reuqer sA .oacilpa ed ad ocifcepse o

odnes

on

sdaerht

otnemaevahc

,missA .oacilpa ad etrap mezaf euq sdaerht setnerefid sa ertne ,sdaerht ed acetoilbib ad sdaerht ed rodanolacse olep ,odubirtsid odasep ossecorp od rodassecorp ed opmet O .sadinifed marof sdaerht sa lauq on odasep ossecorp od otnemanolacse o atucexe ,sdaerht ecehnoc on ametsis od oelcn O

.)sdaerht a ,amrof

ed acetoilbib( oacilpa alep odazilaer sdaerht ed otnemaicnereg atseD .otnemanolacse ed somtirogla so meratnemelpmi

ed mla ,.cte ,raeuqolb ,riurtsed ,rairc arap savitimirp meulcni sotnemidecorp setsE .sdaerht ed otnemaicnereg ed sotnemidecorp so atnemelpmi euq

acetoilbib amu rop ,oirusu ed levn a atief oatnemelpmi a ,oledom etseN

1:N oledoM

.)ynam-ot-ynam( N:M e ,)eno-ot-eno( 1:1 ,)eno-ot-ynam( 1:N :os soledom sO .lanoicarepo ametsis on sdaerht sad oatneserper ed amrof

a macifitnedi euq , sdaerht ed sacetoilbib sad oatnemelpmi a arap socisb soledom srt metsix E .sacetoilbib rop sadatnemelpmi res medop sdaerhT

sdaerhT ed oatnemelpmI

.ossecorp on sdaerht sa sadot animret odasep ossecorp od oanimret a euq acitsretcarac artuO .odasep ossecorp o odot

56

ametsis od oelcn on sdaerht ed oatnemelpmi ad snegatnavsed e snegatnaV

.oelcn o evlovne sdaerht ed otnemaevahc o ,otnatroP .oelcn on daerht amu rednopserroc

oacilpa ed amargorp on daerht adac A .lanoicarepo ametsis olep sadazilaer os sdaerht ed .cte ,oiurtsed ,oairc ed searepo sa ,amrof atseD

.sodasep sossecorp e sdaerht erbos otxetnoc ed seamrofni mtnam oelcn O .lanoicarepo ametsis od oelcn o arap oucexe a odnassap ,otxetnoc

ed acort amu atucexe e adamahc ad sortemrap so atocapme euq acetoilbib ed anitor amu ednopserroc sdaerht ed oalupinam ed avitimirp adac

a ,missA .ametsis od oelcn on atief sdaerht ed aicnreg a ,oledom etseN

1:1 oledoM

.setnerefid serodassecorp me rador medop on odasep ossecorp omsem od

;raunitnoc redop ossecorp od daerht artuo ed rasepa ,odasep ossecorp odot

snegatnavseD

;oacilpa adac a odauqeda

;)ametsis/oirusu( oucexe

snegatnaV

ed odom ed acort on

,lenrek

o evlovne on sdaerht ed otnemaevahC

omtirogla ed ahlocse :oacilpa ad etnedneped res edop otnemanolacsE

.acetoilbib

ad oalatsni a lat arap odnatsab ,OS reuqlauq me rador edoP

aieuqolb lenrek o e

setnaeuqolb os ametsis ed sadamahc sad airoiaM

sdaerht sauD .serodassecorp a sodasep sossecorp aicossa s oelcn O

66

;) sgra* diov ,)oacnuf*(* diov ,birta* t_rtta_daerhtp tsnoc ,diht* t_daerhtp (etaerc_daerhtp tni

avitimirp a moc atief daerht amu ed oairc a ,sdaerhtp moC .sdaerht odnazilitu ++C ,C samargorp ed otnemivlovnesed o oamargorp ed ecafretni amu enifed )sdaerhT XISOP( etimrep euq

sdaerhtp acetoilbib A

)sdaerhT XISOP( sdaerhtp


.oelcn olep saditnam os saruturtse saus e ,rodassecorp mu me adanolacse res edop euq edadinu

amu macifitnedi ametsis od sdaerht sA .oamargorp ed ecafretni a mecerefo e OS oa sievsivni os oirusu od sdaerht sA .ametsis od sdaerht e oirusu

od sdaerht ertne onitsid amu otnatrop etsixE .oirusu sdaerht sa raepam arap sadazilitu ores euq ametsis sdaerht ed oremn o atsuja rodamargorp o euq odnes ,oazinorcnis a e otnemanolacse o omoc missa ,oirusu levn a odazilaer sdaerht ed otnemaicnereg O .ametsis sdaerht N me sadaepam os euq ,sdaerht M retnoc edop oirusu ed ossecorp adac ,oledom etseN

N:M oledoM

.ametsis od ohnepmesed on ovitacifingis otcapmi mu atneserper euq o oelcn

snegatnavseD

;serodassecorp setnerefid me odasep ossecorp

snegatnaV

omsem od sdaerht sairv etnemaenatlumis ranolacse edop oelcn O

;odasep ossecorp ed on e daerht ed levn a oieuqolb O

.dedaerhtitlum mbmat res medop OS od sanitor sA

o evlovne odasep ossecorp omsem od ortned sdaerht ed otnemaevahC

76

.etnerrocnoc amargorp mu ed oatnemelpmi a arap savitimirp satsed osu o artsnomed ,C me otircse ,riuges a amargorp O .otnemugra odnuges omoc LLUN edop ,onroter ed rolav ajesed on rodamargorp o eS rassap

.daerht alep odaluclac

onroter ed rolav mu e ,ahlaf ed osac me ovitagen rolav mu ,adidecus meb oarepo ed osac me 0 : rop adacifitnedi

sgra

me serolav ranroter edop daerht A a euq ta raeuqolb es

daerht

daerht

;) sgra** diov ,diht t_daerhtp (nioj_daerhtp


avitimirp A

.onuf amu ed oproc on odinifed

daerht

amu rop odatucexe res a seurtsni ed otnujnoc o ,++C/C mE .0 rolav o odanroter oarepo ad ossecus ed osac oN

.odilv orietnop mu

.daerht avon a

:orre od azerutan a acidni odanroter rolav o e adairc on daerht a ,ahlaf oarepo a eS .adairc

daerht

a arap sortemrap omoc sodassap sodad

, otsi ,daerht ad oucexe ed opocse ,. siaicepse sotubirta snugla rinifed

od

,diht

ortemrap O .sodnamoc ed reuqlauq ocolb mu me recerapa edop euq

pthread_t,

daerht ad rodacifitnedi o ,adamahc ad onroter on ,mtnoc

NULL

os ,

otnemugra

o odassap rof eS

contm

sod airmem ed oeredne o

sgra .tluafed

sotubirta so sodazilitu

.).cte ,1:N oledom uo 1:1 oledom ad otnemanolacse ed acitlop( oa etimrep

daerht

rodamargorp

birta

rairc arap soirssecen sosrucer so iussop on ametsis O

:NIAGAE

on rtta uo )daerht( adatucexe res a onuf ad emon

o :TLUAFE

.odazilaicini otubirta mu on rtta :LAVNIE

void * Thread0 () { #include <pthread.h> #include <stdio.h>


.enimret amu a etimrep

thid

,adairc opit

86

.setnerrocnoc samargorp ed otnemivlovnesed on sodasep sossecorp ed e sdaerht ed osu o erapmoC .1

.niam daerht ad onimrt o moc erroco euq o ,animret odasep ossecorp o es sadanimile os odasep ossecorp

mu me sadinifed sdaerht sa siop ,enimret e oucexe a eunitnoc niam daerht a euq edepmi siop ,levsnepsidni nioj_daerhtp avitimirp ad osu O .1t daerht ad onimrt o moc adadroca res e ,)LLUN,1t(nioj_daerhtp oarepo a moc ,aieuqolb es niam daerht a ,0t daerht ad onimrt o spA .enimret 0t daerht a euq arepse a ,)LLUN,0t(nioj_daerhtp avitimirp a moc ,aieuqolb es e )oucexe me sdaerht srt ritsixe a otne odnassap( 1t daerht a airc niam daerht

a ,riuges A .rodassecorp od osu o rahlitrapmoc a massap adairc daerht a e niam daerht a ,avitimirp atsed oucexe ad ritrap A .etaerc_daerhtp avitimirp

ad adamahc a moc ,ot daerht a airc euq ,niam daerht an aemoc oucexe A .amargorp od niam onuf ad ogidc o atucexe euq ,niam daerht a e ,991 e 001 ertne serolav so emirpmi euq 1daerhT onuf ad ogidc o atucexe euq ,1t daerht amu ,99 e 0 ertne serolav so emirpmi euq 0daerhT onuf ad ogidc o atucexe euq ,ot daerht amu ,sdaerht srt rop odamrof amica amargorp O

Exerccios
} int main(){ pthread_t t0, t1; int ret0, ret1; } void * Thread1 () { int i; for(i=100;i<200;i++) printf(" Thread1 - %d\n",i); } int i; for(i=1;i<100;i++) printf(" Thread0 - %d\n",i); ret0 = pthread_create(&t0, NULL, Thread0,NULL) ; ret1 = pthread_create(&t1, NULL, Thread1,NULL) ; pthread_join(t0,NULL); pthread_join(t1,NULL); printf("Main ....\n");

96

.xuniL lanoicarepo ametsis on krof moc etnemelpmi o e sossecorp 5 ominm on moc ofarg mu anifeD .krof avitimirp ad oucexe an xuniL lanoicarepo ametsis olep sadatucexe sea sa avercseD .oledom adac ed snegatnavsed/snegatnav odnanoicaler ,sdaerht ed oatnemelpmi ed sedadilibissop sa erbos elaF .nioj/krof ed osu o moc ,etnednopserroc amargorp o avercse e aicncederp ed ofarg o aurtsnoc .5 .6 .7

)7s(

;3 + y = z

)6s( ; g + x = y )5s( ; h + m = x )4s( ; h + n = m )3s( ; a + g = h )2s( ; k + d = g )1s( ; f + e = d )0s( ; c + b = a .nioj/krof ed osu o moc etnerrocnoc amargorp o avercse e aicndecerp ed ofarg o aaf ,riuges a sodatneserpa sodnamoc so odnaredisnoC ; 9s ; 1tnuoc nioj :4L ; 8s ; 2tnuoc nioj :3L ; 6s :2L ; 3L ot og ; 5s ; 2L krof ; 3s :1L ; 4 L ot o g ; 7 s ; 4 s ; 2 s ; 1L krof ; 1s ; 2 = 2tnuoc ; 2 = 1tnuoc .3

.riuges a odatneserpa etnerrocnoc amargorp od aicndecerp ed ofarg o aaF .2

4.

,); 2+b = a :0S .xe( sodnamoc 8 ominm on ed otnujnoc mu anifeD

Bibliografia

3. Escalonamento
07

17

;).cte ,salif arap sorietnop

:os sacipt seamrofnI .ossecorp oa setnerefer seamrofni sa mtnam euq ,rotircsed ortsiger mu rop ametsis on sodatneserper os sossecorp sO

kcolB lortnoC ssecorP

.)opmet ed megassap .xe(

:salif sartuo adnia iussop ametsis O so mtnoc euq )tsil ydaer a( alif

.rador a sotpa sossecorp

amu me UPC alep marepse ratucexe a sotpa

sossecorp siamed so e )rodassecorp o mted euq o( gninnur ossecorp mu etsixe ,rodassecorpinu sametsis soN .lautriv UPC airprp aus met ossecorp

adac euq ranigami es-edop ,missA .laer UPC a euq od ronem edadicolev amu moc mrop ,UPC airprp aus a e s s e v it ossecorp adac es omoc

oirusu o araP .oucexe me otse euq sossecorp so ertne odubirtsid rodassecorp ed od opmet amu o euqrop erroco oss I me .)omsilelarap-oduesp( samargorp setnerefid

omsilelarap

osuli

odnairc

,oucexe

so ertne odahlitrapmoc UPC ad osu o oamargorpitlum moc sametsis mE

.TN swodniW e xuniL on otnemanolacsE .salelarap saniuqm me sossecorp ed otnemanolacsE .otnemanolacse ed somtiroglA .socisB sotiecnoC

3.1 Conceitos Bsicos

;O/I odnarepse sossecorp so mtnoc :sovitisopsid ed salif

sotneve ed arepse a sodaeuqolb sossecorp so mtnoc :sotneve ed salif

;.cte ,dekcolb ,gninnur ,ydaer :ossecorp od odatse

;retnuoc margorp

;UPC ad serodartsiger

,sedadiroirp - omtirogla od medneped( otnemanolacse ed oamrofni

27

0 ocsiD

9cseD

5cseD

0cseD

mirP

tlU tsiL ydaeR


.21 ossecorp o moc ,1ocsid od alif a e 31 e 7 sossecorp so moc ,0ocsid od alif a ,9 e 5,0 sossecorp so otse lauq an ,rador sotpa sossecorp ed alif a macifilpmexe oxiaba sarugif sA .lanoicarepo ametsis olep sadaicnereg etnemlaugi

os ).cte ,socirfirep ed salif ,tsil ydaer( ametsis on setnetsixe salif sA

.odanimile rotircsed ortsiger ues ,animret ossecorp o odnauQ .serotircsed ed alebat a odaroprocni e odairc rotircsed ortsiger mu ,oditembus ossecorp mu odnauQ .oucexe me ossecorp mu odnevercsed mu adac ,serotircsed ed alebat amu aicnereg lanoicarepo ametsis O

.cte ,sotreba soviuqra ,ossecorp

;.cte ,sanigp ed alebat a arap matnopa euq serodartsiger ,etimil

e esab serodartsiger ed rolav :airmem ed aicnreg arap oamrofnI

;.cte ,setimil ,adazilitu UPC ed opmet :orazilibatnoc ed oamrofnI

oa sodacola sovitisopsid ed atsil :O/I ed odatse ed oamrofni

37

omreT ognoL ed serodanolacsE

.omret oneuqep ed e omret ognol ed res medoP .otnemanolacsE ed acitloP a matnemelpmi euq lanoicarepo ametsis od sossecorp os serodanolacse sO

.ratucexe arap sotnorp airmem an samargorp soirv so ertne UPC ad acort a otnemanolacsE .ossecorp ortuo a eugertne UPC a O/I zaf amargorp

o odnauq ,UPC ad osu o razimito arap ,missA .O/I rop arepse e oucexe ed aicnqes amu amargorp mu ed oucexe A .somsem solep adahlitrapmoc UPC a e airmem an mediser sossecorp soirv oamargorpitlum moC

UPC ad otnemanolacsE

lanoicarepO ametsiS olep sadaicnereg saliF

tlU

21cseD

mirP 1 ocsiD

tlU 31cseD 7cseD mirP

47

;)otxetnoc ed oaruatser( aniuqm ed serodartsiger son )ossecorp od rotircsed on uo ahlip an sodanezamra(

:sea setniuges sa atucexe lat araP .)UPC ad rodanolacsE( omreT oneuqeP ed rodanolacsE olep odanoiceles ossecorp o arap UPC ad agertne alep levsnopser rodanolacse od etnenopmoc o rehctapsid O

rehctapsiD

.airmem an ovon mu racoloc arap ,ossecorp mu ed onimrt oa atucexe omret ognol ed o euq otnauqne ,oucexe o gesm 02 arap ossecorp a mu anoiceles roP .omret o m r et ognol ed oneuqep ed o euq ed rodanolacse

adac

,olpmexe o m r et

etnemetneqerf O .oucexe A

siam ed

otium

atucexe a

oneuqep ed

rodanolacse setse ertne

aicnqerf

serodanolacse

sopit

siod

anerefid

.rador arap acoloc o e ,)tsil ydaer an otse euq( sotpa so ertne ,ossecorp mu manoiceles )UPC ad serodanolacsE( omret oneuqep ed serodanolacse sO

omreT oneuqeP ed serodanolacsE

.)... ,swodniW ,soD ,xinU( sovitaretni sametsis me metsixe on etnemlamron omret ognol ed serodanolacsE .rodassecorp o rahnag arap omret oneuqep ed rodanolacse olep odanoiceles res edno ed ,tsil ydaer an odiresni ossecorp o ,airmem an zev amU .oucexe arap airmem an sodagerrac meres arap atsil atsed sossecorp manoiceles ed atsil amu me omret ognol ed serodanolacse so ,ocsid on os soirusu solep soditembus ,oucexe so

sodacoloc

sossecorp

lauq on ,hctaB opit od lanoicarepo ametsis mu ,olpmexe rop ,es-odnaredisnoC

odanoiceles ossecorp od lareg osu ed serodartsiger so agerrac

.)oucexe a arapsid( retnuoC margorP o agerrac

3.2 Algoritmos de escalonamento

57

.opmet ed sedadinu 6 ed oucexe ed oidm opmet O .opmet ed sedadinu 41 alif an racif ,ajes uo ,7P e 3P ed onimrt o spa araemoc 5P ed oucexe a ,missA .adagehc ed medro me tsil ydaer an sodiresni ,oucexe ed sopmet

sovitcepser sues moc ,)5P e 7P ,3P( sossecorp srt artsom amica arugif A

SFCF moc tsiL ydaeR

tlU

5P

7P

21

3P

mirP

.atsil ad oriemirp o arap adacola adarebil UPC a odnauQ .2

;ydaer atsil ad lanif on artne ratucexe arap otnorp ossecorP .1

.ebecer a euq oriemirp o UPC a atisiuqer euq ossecorp oriemirp o ,omtirogla etseN

)devreS-tsriF-emoC-tsriF( sossecorp ed aliF

:1 omtiroglA

.otnemanolacse ed somtirogla siapicnirp so sodatneserpa ores riuges A

gniludehcS ed somtiroglA

:os somtirogla sod sovitejbo sO .otnemanolacse ed sacitlop sa matnemelpmi somtirogla sO

;atsopser ed opmet o raziminiM

;opmet ed edadinu rop sodatucexe sossecorp ed oremn o razimixaM

.UPC ed opmet o etnememrofinu riubirtsiD

67

:os alif an arepse ed sopmet so ,omtirogla etse araP

FJS moc tsiL ydaeR

tlU

21

3P

5P

7P

mirP

.)opmet ronem ed atissecen euq o( edadiroirp roiam ed ossecorp oa adacola upc a e )UPC ed opmet omixrp( adaicossa edadiroirp amu met ossecorp adac siop ,sedadiroirp me odaesab omtirogla etsE .opmet sonem rop UPC a razilitu ri euq ossecorp oa adubirta ervil atse UPC a odnauQ .UPC ed oapuco ed opmet omixrp ues o ossecorp adac a aicossa FJS O

)tsriF boJ tsetrohS

FJS( oriemirp sossecorp seroneM :2 omtiroglA

41 = )2 + 21( :5P

21 :7 P

0 :3 P

:os alif an arepse ed sopmet so ,amica olpmexe oN .ataidemi res eved atsopser a euq me ametsis mu a levivni anrot es atsopser ed opmet o e sodadrater os alif an sossecorp siamed sO .opmet otium rop maziloponom o rodassecorp o merahnag oa ,adas e adartne ed searepo ed acuop

e otnemassecorp ed edadissecen atium meussop euq , otsi ,dnuob UPC sossecorp siop ,sovitaretni sametsis arap odauqedani omtirogla etsE

77

.ovitpmeerp on omtiroglA .edadiroirp aus a moc odroca ed ,alif an odacoloc erpmes ydaer alif an odnagehc ossecorp mU )f

.ovitpmeerp omtirogla o euq es-zid ,osac etseN .alif an acif oirrtnoc osac ,upc a ahnag ,roiam rof eS .odnador tse euq ossecorp od a moc adarapmoc edadiroirp aus met ydaer alif an odnagehc ossecorp mU )e

:os savitanretla sA .odnador tse euq ossecorp od a euq od atla siam edadiroirp moc

ossecorp mu ed tsil ydaer an adagehc a etnatropmi otcepsa ortuO

.otinif opmet mu me seucexe saus ,amrof atsed ,odnitnarag ,edadiroirp axiab ed sossecorp sod edadiroirp a ratnemercni sopmet me sopmet ed edadilibissop amu ,ol-noiculos araP .edadiroirp axiab moc sossecorp ed adinifedni oagretsop ed o rigrus edop euq amelborp mu sedadiroirp me odaesab omtirogla soN .ronem a 0 sortuo ,roiam a 0 sametsis snugla mE .ossecorp od edadiroirp a acidni euq )N..0( oairav ed opmac mu etsixe sedadiroirp me odaesab somtirogla soN

.)edadiroirp atse( rolav etse a etnednopserroc oisop an tsil ydaer an ol-coloc e ,ossecorp adac arap UPC ed

osu ed opmet omixrp o ranimreted ,esilna atsen esab moC .ossecorp adac ed oucexe ad acirtsih esilna amu rezaf adatoda oulos amU .ossecorp adac arap UPC ed opmet omixrp ranimreted FJS od amelborp O

.opmet ed sedadinu 41 ed arepse ed opmet roiam o SFCF on euq otnauqne ,opmet ed sedadinu 6 arepse alif an opmet siam acif euq ossecorp O .ronem alif an arepse ed opmet o ,roiretna omtirogla oa oaler mE

2 :5 P

0 :7 P

6 = )4+2( :3P

87

etnemavon rahnag ,oriemirp o mbmat res omoC .tsil ydaer an omitl omoc odiresni res e opmet ed aitaf amu ratucexe omsem o ,seucexe srt adnia odnatlaf e tsil ydaer an 3P ossecorp o etnemos odnatser omseM .seucexe 3 spa 7P ossecorp o e seucexe saud spa tsil yder ad ias 5P ossecorp O .7P ossecorp o spa ,tsil ydaer ad lanif on odacoloc res e opmet ed aitaf

amu

rop ratucexe ,rodassecorp o rahnag 5P ossecorp O .tsil ydaer ad lanif

on odacoloc res e opmet ed aitaf amu rop ratucexe ,rodassecorp o rahnag 7P ossecorp o ,opmet ed sedadinu 2 ed ajes opmet ed aitaf a euq odnopuS

niboR dnuoR moc tsiL ydaeR

tlU

21

3P

5P

7P

mirP

.rodassecorp

;tsil ydaer ad lanif on odiresnier

:etniuges o omtirogla od otnemanoicnuf O .rodassecorp o moc racif edop ossecorp o euq omixm opmet mu etsixe e ralucric alif amu ratucexe a sotpa sossecorp ed atsil a ,omtirogla etseN

niboR-dnuoR :3 omtiroglA

.sovitpmeerp res meved somtirogla so ,sossecorp snugla arap siatnemadnuf sezev satium os atsopser ed sopmet so siauq son ,laer opmet ed sametsis mE

;tsil ydaer ad ossecorp oriemirp o rageP

odatpmeerp

,opmet

ed

aitaf

amu

rop

atucexe

ossecorp

ahnag

odanoiceles

tsil

ydaer

ad

ossecorp

oriemirp

97

.seronem sedadiroirp

:sacitsretcarac setniuges sa meussop somtirogla setsE .otnemanolacse ed salif salpitlm ed oazilitu a adagerpme res a oulos artuo amU

salif salpitlM mazilitu euq somtiroglA

.gesilim 001-01 ed mairav ecils emit ed snumoc serolaV .otxetnoc ed acort moc otsag opmet o atnemua oneuqep otium mutnauQ .)SFCF( alif ed omtirogla od o-odnamixorpa ,omtirogla o areneged ednarg otium mutnauq mU .mutnauq od oinifed a omtirogla etsed oatnemelpmi an arap amelborp ortuo mU .sodnugesorcim

001-01 ed mairav otxetnoc ed oaruatser/otnemavlas ed socipt sopmeT

;ossecorp od rotircsed o arap serodartsiger so sodot ed rolav o revom atimrep

:edneped opmet

etsE

.otxetnoc ed

oaruatser ed e otxetnoc ed otnemavlas opmet olep odanimreted daehrevo o raredisnoc a otcepsa mU .rodassecorp od osu o eziloponom ossecorp

mu euq ative siop ,sovitaretni sametsis soa odauqeda omtirogla etsE

.tsil ydaer an sossecorp ed oremn od etnemetnednepedni ,amsem a erpmes res rodanolacse od oa a euq acifingis o t sI .rodassecorp o

;airmem ed

edadicolev aD

;serodartsiger ed oremn oD

euq ourtsni amu ,olpmexe roP .siaicepse seurtsni ed aicntsixe aD

;sopurg me sodacifissalc os sossecorp sO

;opurg adac arap alif amu etsixE

;omtirogla oirprp ues ret edop alif adaC

moc salif siamed sa erbos atulosba edadiroirp ret edop alif

amU

08

.riuges a arugif ,rodassecorp reuqlauq rop adasseca res edop euq labolg airmem amu etsixe ,mumoc airmem moC .adubirtsid airmem moc salelarap saniuqm

e mumoc airmem moc salelarap saniuqm :os nylF ed oacifissalc an ,saniuqm ed sopit sioD .etnednepedni amrof ed marepo euq serodassecorp rop satsopmoc os ]2791 n y l F[ DMIM o p it od salelarap sarutetiuqra sA

e edadiroirp axiab siam ed salif arap sossecorp ratnemivom arap soirtirc ,edadiroirp atla siam ed salif arap sossecorp ratnemivom arap soirtirc ,salif ed oremn o odinifed res eved ,somtirogla setseN .sedadiroirp sa otnatrop odnairav ,salif sa ertne mevom es sossecorp so ,osac etseN .oailavaer

euq

3.3 Escalonamento de Processos em Mquinas Paralelas


.raicini eved ossecorp o alif lauq me ranimreted arap soirtirc moc salif salpitlm ed aicntsixe a omtirogla etse a avitanretla amU .rodassecorp o mehnag edadiroirp axiab ed salif me sossecorp es-arugessa ,amrof atseD .alif adac a adubirta opmet ed aitaf amu ritsixe edop ,alif amu ed adinifedni oagretsop ed amelborp o rative araP

18

zaf ertsem O .oirusu ed sossecorp

etnemos mador serodassecorp siamed

so ,rodassecorp mu me erpmes mador lenrek od senuf sA :ovarcse-ertseM

.ocirtmis e etnautulf ertsem ,ovarcse/ertsem res medop snegadroba sA .serodassecorp setnerefid rapuco edop ossecorp o setnerefid sopmet me odnauq acimnid e rodassecorp omse m res on ador ossecorp a ts E o odnauq acittse mu .acimnid ehl uo acittse ametsis

edop

oaicossa

.ossecorp

iubirta

lanoicarepo

o ervil acif rodassecorp mu euq erpmes , otsi ,adnamed bos ,serodassecorp a sossecorp aicossa lanoicarepo ametsis o e sosrucer omoc sodatart os serodassecorp sO .lanoicarepo ametsis ocin mu ed elortnoc bos airmem mahlitrapmoc solep adahlitrapmoc euq serodassecorp ed otnujnoc sotpa sossecorp ed O o bos macif

.serodassecorp alif acin amu

,rador

mumoc airmem an riussop medop ,adahlitrapmoc airmem moc sametsis sO

adahlitrapmoc airmem moc sametsis me otnemanolacsE

.rodassecorp ortuo ed airmem a rasseca edop on e airmem aus a iussop rodassecorp adac ,amica arugif aN

mumoC airmeM meS alelaraP aniuqM

3P

2P

1P

0P

airmeM

airmeM

airmeM

airmeM

.riuges a arugif an adartsom mumoc airmem mes aniuqm amU .labolg airmem amu mahlitrapmoc euq ,serodassecorp ortauq rop adamrof ,mumoc airmem moc alelarap aniuqm amu acifilpmexe amica arugif A

28

.sodahlitrapmoc sodad so rasseca arap sacitrc sees metsixe euq odnes ,etnemaenatlumis serodassecorp solpitlm rop odasseca res edop lanoicarepo ametsis o :acirtmis oarugifnoC

.lanoicarepo ametsis od ogidc o atucexe zev rop rodassecorp mu etnemoS .acitrc

oes amu omoc odatart orietni lanoicarepo ametsis o :etnautulf ertseM

;atucexe sa ertsem o etnemos euqrop ametsis ed sadamahc sa azilaires

ertsem oa odidep zaf ,)ametsis ed adamahc( oivres asicerp ovarcse o es e otnemanolacse

snegatnaV

;ratnemelpmi e ratejorp ed selpmiS

.ossecorp ocin mu ed alelarap oucexe

etimreP

snegatnavseD

;agrac atium moc acif on etnemlamron ertsem O

olagrag mu ranrot es edop ertsem O

.ametsis o odot arap ertsem od ahlaf a

:snegatnaV

;sodazilitu

etnematelpmoc os serodassecorp

so sodoT

. ossecorp mu ed alelarap oucexe etimreP

snegatnavseD

.aunitnoc ertsem od olagrag O

:snegatnaV

38

aus ed lanif o ta rodassecorp etsen ecenamrep ossecorp o oacola a adazilaer ed siopeD .oucexe ad setna odinifed odatucexe res ossecorp o edno rodassecorp o odnauq ocittse elE .ocimnid uo ocittse res

edop labolg omtirogla mu ,oacifissalc atse moc odroca eD .otnemanolacse ed somtirogla sod oacifissalc amu adatneserpa ]yksnizoG[ mE .agrac ed otnemaecnalab

etse retbo arap sossecorp ed oargim a razilitu es-edoP .sodagerracerbos sn e sosoico amu ed sn ametsis on res matsixeoc eved euq es-rative ed agrac arap A adaecnalab .)

amrof

adubirtsid

ohlabart

tuphguorht(

ametsis od labolg ohnepmesed mob mu ritnarag a arienam ed atief res eved etnemacimanid sodairc sossecorp sod oacola a ,osac odnuges oN .sossecorp sovon sodairc os on e sossecorp ed oargim erroco oN .oucexe aus ed lanif o ta n omsem on mecenamrep e oazilaicini a etnarud eder ad serodassecorp sn soa sodacola os sossecorp so ,osac oriemirp oN .oucexe

a etnarud rairav medop sossecorp ed oremn o euq saleuqa os sacimnid seacilpA .aretla es on sossecorp ed ofarg O .otnemassecorp od onimrt o ta acifidom es on e oucexe aus ed oicni on odicehnoc sossecorp ed oremn o ed acittse oremn oacilpa oa otnauq amu mE .acimnid uo acittse oacilpa omoc amU

,sossecorp

adacifissalc

,alelarap

adahlitrapmoc airmem mes sametsis me otnemanolacsE

;ksat acin amu ed alelarap oucexe etimreP

.litsrev siam oarugifnoC

:snegatnavseD

ratnemelpmi e ratejorp ed licfid siaM

etnartneer lenrek reuqeR

etnemetnerefid satircse sacitrc seeS

etnemetnerrocnoc sadatucexe ametsis ed sadamahc satiuM

48

:marof xuniL od rodanolacse o arap sodinifed sotisiuqer so ,otnemivlovnesed ues mE

xuniL lanoicarepo ametsis on otnemanolacsE

.PX/0002 swodniW e xuniL sianoicarepo sametsis son sodazilitu otnemanolacse ed somtirogla so sodatneserpa ores riuges A

a atneserper oaicogen ed acitlop A .odargim res ossecorp o rodassecorp euq arap uo odairc res ossecorp o ametsis od rodassecorp euq

me animreted oazilacol ed acitlop A .serodassecorp ertne aicnrefsnart ed saferat salep levsnopser aicnrefsnart ed acitlop A .serodassecorp sod agrac a sovitaler ed acitlop sodad A sod otnemanezamra ed acitlop a olep e levsnopser ed

oamrofni

acitlop a ,aicnrefsnart ed acitlop a ,oamrofni ed acitlop a matnemelpmi euq ,socisb sotnemele ortauq ed sodutitsnoc os somtirogla sO

on uo ametsis od serodassecorp sortuo so mevlovne odnauq savitarepooc res medop sale ,sesiced s otnauQ .adubirtsid amrof ed mbmat erroco oacola ed osiced a ,ametsis od serodassecorp sod ognol oa adubirtsid serodassecorp sod agrac a erbos oamrofni a sodubirtsid somtirogla mE .adazilartnec mbmat oacola ed osiced a e ,ametsis od rodassecorp mu me aditnam serodassecorp sod agrac a erbos oamrofni a

sodazilartnec somtirogla mE .ossecorp o odatucexe res edno rodassecorp od ahlocse odanoicaler oacifissalc ad otcepsa etnatropmi ortuO .sossecorp ed oargim a rerroco edop ,agrac ed otnemaecnalab o rarohlem araP .sodairc os sossecorp so euq adidem atief rodassecorp od osiced a socimnid somtirogla soN .oucexe

3.4 Escalonamento no Linux e no Windows 2000/XP


.osiced ed ossecorp o etnarud serodassecorp so ertne oaretni .oaicogen oazilacol .sn sortuo so mevlovne on odnauq savitarepooc

58

:sacitrc sadacifitsuj amugla airfos xuniL od otnemanolacse o ,6.2 a maredecetna euq sesrev saN

.meraeuqolb es ta uo meranimret ta matucexe SFCF sossecorP .edadiroirp roiam ed ossecorp o ehlocse rodanolacse o e ,edadiroirp

amu meussop niboR dnuoR laer opmet ed sossecorP .oriemirp rodassecorp o ahnag erpmes ele ,rador arap laer opmet ed ossecorp mu etsixe eS .sossecorp siamed so sodot erbos edadiroirp meussop laer opmet ed sossecorP .niboR dnuoR e SFCF os somtirogla so laer opmet ed sossecorp araP .niboR dnuoR o omtirogla o sovitaretni sossecorp so araP .laer opmet e )gnirahs-emit(sovitaretni sossecorp :odasu gniludehcs ed omtirogla o menifed sacitsretcarac sajuc ,sossecorp ed sopit siod aredisnoc xuniL O

.)gninnur uonrot es euq o( oucexe arap ossecorp ovon mu ranoiceles ri euq ,rodanolacse o amahc lenrek o ,odnador avatse euq ossecorp od a euq od roiam eS .gninnur odatse o arap assap euq ossecorp od edadiroirp a acifirev lenrek O .ovitpmeerp xuniL od rodanolacse O .edadiroirp roiam a iussop euq ossecorp o arap UPC a agertne rodanolacse O .etnemacimanid adaluclacer euq ,edadiroirp amu iussop xuniL on ossecorp adaC .dnuob UPC sossecorp soa oaler me ,sovitaretni

sossecorp so ecerovaf xuniL o ,atsopser ed opmet mob mu recerefo a arienam eD .O/I ed searepo sacuop mezaf e UPC atium masu ,oirrtnoc .ovitaretni omoc odacifissalc res mbmat

oa ,dnuob UPC sossecorP

odnedop ,oirusu o moc oaretni alep e adas e adartne ed searepo ed oremn omsstla olep aziretcarac es siop ,dnuob O/I ossecorp mu etnemacipit sotxet ed rotide mu ,olpmexe roP .dnuob UPC e dnuob O/I me sossecorp so acifissalc es etnemlanoicidart ,otisiuqer oriemirp oa oaler mE

;adavele agrac

moc omsem ,sovitaretni samargorp me ecnamrofrep aob ratneserpA

;UPC ad opmet o atsuj arienam ed riubirtsiD

;PMS saniuqm me etneicife reS

.laer opmet arap etropus riussoP

68

.ecnamrofrep an etnemavitagen odnaicneulfni ,otnemassecorp ed agracerbos amu odnacovorp ,sodasu res siam oredop on sehcac me setnetsixe arutnevrop ossecorp od sodad ,odnecetnoca otsI .etnemaiverp

odnador avatse lauq on eleuqad etnerefid rodassecorp mu rop odatucexe res redop e ,labolg euq ,tsil ydaer an odacolocer atelpmoc es atse odnauq

,adas e adartne ed oarepo amu uoticilos euqrop ,olpmexe rop ,odipmorretni ossecorp mu ,odnugeS .ametsis od ohnepmesed on levredisnoc adeuq amu me raterraca edop serodassecorp sod oieuqolb etse serodassecorp ed odavele oremn mu araP .adarebil ajes amsem a euq ta rarepse matissecen siamed so tsil ydaer a odnasseca tse rodassecorp mu eS .serodassecorp sod etrap rop tsil ydaer a ovisulcxe etnemautum a osseca ed edadissecen a oriemirp :sazerutan saud ed os samelborp so ,PMS saniuqm san labolg tsil ydaer amu ed aicntsixe a ,6.2 a seroiretna sesrev san ,xuniL od rodanolacse oa sacitrc sad otcepsa odnuges oa etnerefeR .ametsis od ohnepmesed o etnememrone razilanep airedop opmet etse ,sossecorp ed ednarg otium oremn mu moc seacilpa araP .ovitacifingis on opmet etse sossecorp ed oneuqep oremn mu moc seacilpa araP .sedadiroirp sa raluclacer rodanolacse o arap oirssecen opmet o atnemua ,ametsis on sossecorp ed oremn o odnatnemuA .rodanolacse o arap oucexe ed opmet atneserper sedadiroirp ed olucccer etsE .rador a omixrp o anoiceles otne e sodot ed edadiroirp a aluclacer rodanolacse o ,odaripxe ecilsemit ues moc merevitse sossecorp so sodot odnauQ .edadiroirp roiam a moc odaripxe on ossecorp o anoiceles ,odamahc odnauq ,rodanolacse O .odaripxe omoc odacram ossecorp o ,orez a agehc ecilsemit o odnauQ .)ecilsemit( opmet ed aitaf amu rop UPC a ahnag ossecorp o ,odanoiceles zev amU .oucexe ed opmet me otnematropmoc ues me e )eciN( acisb edadiroirp amu me adaesab ,edadiroirp amu odniussop mu adac ,sossecorp ed alif amu mtnam ,ossi rezaf araP .rodassecorp o ragertne arap edadiroirp roiam ed ossecorp o ranoiceles eved rodanolacse O

.PMS saniuqm me labolg tsil ydaer amU

)b

;ametsis on sossecorp ed oremn od otnemua oa etnemlanoicroporp rodanolacse od oucexe ed opmet od otnemuA )a

78

oargim ed daerhT

4P

1 edadiroirP sodaripxE

nP

3P

6P

041 edadiroirP

nP

5P

2P

1 edadiroirP sovitA sotpa ed aliF


.UPC adac arap

sotpa ed alif amu etsixe ,PMS saniuqm mE .sotpa sossecorp ed alif amu azitameuqse riuges a arugif A .serodatnopa ed acort selpmis amu moc ,ovita anrot es odaripxe yarra o ,otnE .sovita yarra od sossecorp so sodot moc aetnoca ossi euq ta adrauga e ,sodaripxe sod alif an odacoloc ,opmet ed aitaf aus animret ossecorp mu odnauQ .sievgeleni etnemairaropmet sossecorp moc ,odaripxe ortuo e rador arap sievgele ,sovita

sossecorp so moc mu ,syarra siod rop adatnemelpmi alif atsE .ratucexe arap sotnorp sossecorp so sodot ed alif amu iussop 6.2 lenrek od rodanolacse O

;rodassecorp

;odagerracerbos

;sossecorp ed oremn od etnemetnednepedni ,rador

:os reludehcs )1(

0 ed odamahc ,3002 ed lanif

on ocilbp odanrot ,6.2 lenrek od rodanolacse od sacitsretcarac siapicnirp sA 6.2 lenreK on otnemanolacsE

arap ossecorp mu ranoiceles arap oucexe ed etnatsnoc opmeT

ametsis o moc omsem sovitaretni samargorp moc ecnamrofrep aoB

;PMS saniuqm me etneicifE

adac arap sotpa ed alif amu moc ,rodassecorp ed edadinifA

.laer opmet a etropuS

88

.oigler od kcit

adac

a ,etnemacidoirep e ,odaecnalabsed atse ametsis o odnauq ,etnematicilpxe adamahc

oargim ed daerht A .sodagerracerbos majetse sortuo

otnauqne sosoico serodassecorp matsixe euq rative aidia ,rodassecorp rop

tsil ydaer amu etsixe omoC .serodassecorp sod osu o raecnalab

arap ,ortuo arap rodassecorp mu ed sossecorp ratnemivom ed onuf a met euq ,

oargim ed daerht amu ador rodassecorp adac me ,etnemlaniF


.)dnuob UPC( sovitaretni on sossecorp

ed edadiroirp a riunimid e )dnuob O/I( sovitaretni sossecorp ed edadiroirp a ratnemua aidi sossecorp so ,missA a e sovitaretni on e sovitaretni me sodacifissalc os

.ossecorp od edadiroirp ed sunb o raluclac arap azilitu

a e ossecorp mu ed odaeuqolb opmet ed aidm a aluclac rodanolacse O .O/I rop odnarepse etnemavon macif e etnemadipar matucexe ,O/I rop odnarepse sodorep sognol rop sodaeuqolb macif euq seleuqa os sovitaretni sossecorP .otnematropmoc ues ed oavresboalep sovitaretni on e sovitaretni me ,rodanolacse olep ,sodacifissalc os sossecorp sO .edadivitaretni ed levn ues o odailava ,oirusu ed sossecorp sod edadiroirp ad oluclc o araP .)niboR dnuoR( rodassecorp o ahnag edadiroirp amsem ed alif ad ossecorp omixrp o ,opmet etse odatogsE .sm 02 ed opmet ed aitaf amu meussop oirusu ed sossecorp so ,041 a 101 edadiroirp ed sievn soN .5 a 5+ ed airav euq ,edadiroirp ed ocimnid sunob ues e

ecin ues ed rolav

o euq ,edadiroirp aus ed amos a oirusu ed sossecorp sod edadiroirp A .edadiroirp ed levn omsem on ,odnador maunitnoc sel e adubirta opmet ed aitaf artuo amu odanimret mahnet edadiroirp ed levn odad mu ed sossecorp so sodot odnauQ .opmet ed aitaf atse ranimret ta matucexe e opmet ed aitaf amu mebecer niboR dnuoR sossecorP .sodatpmeerp os on e oditnam edadiroirp ed levn O .UPC a merarebil etnemairatnulov ta matucexe OFIF sossecorP .acittse edadiroirp amu meussop e ,niboR dnuoR uo OFIF res medop laer opmet ed sossecorp sO .)sovitaretni on uo sovitaretni( oirusu ed sossecorp siamed arap 041 a 101 eD .laer opmet ed sossecorp arap os 001 a 1 ed sedadiroirP .edadiroirp a roiam ,levn o ronem otnauq euq odnes ,edadiroirp ed sievn 041 iussop rodanolacse O

98

.alif an etniuges oisiuqer a ratucexe ed setna opmet otrec mu arepse e ,rerroco on ortuo mu ,daer mu spa ,es rev atnet e ossecorp adac ed sacitstatse samugla mtnam ,ossi araP .ossecorp mu ed arutiel ed searepo sarutuf rapicetna atnet )SA( reludehcS oirtapicetnA O

reludehcS oirtapicetnA

.DAER searepo sad seisiuqer sad oaziroirp a moc

e ronem

enildaed mu oiubirta moc ,edadivitaretni ad otnemua o etnatropmi otcepsa ortuO .seisiuqer ed adinifedni oagretsop revah on euq etnarag enildaed o e )seisiuqer sad oacifissalc alep( sadaziminim os )kees( etoebac ad otnemanoicisop ed searepo sa euq arugessa acitlop atsE .uoripxe enildaed ojuc seisiuqer sad oucexe a odnitnarag ,alif ad medro a odniuges seisiuqer sa arapsid rodanolacse o otne ,aripxe enildaed mu eS .salif sad medro a odniuges ,seisiuqer sa arapsid rodanolacse O .oisiuqer aus a etnednopserroc oisop an ,)ETIRW uo DAER( adairporpa alif an adiresni ,aditembus oisiuqer a odnauQ .ges 5 ed enildaed mu amu e moc ,ETIRW ed alif

sm 005 ed enildaed mu moc ,DAER ed alif amu :salif saud atnemelpmi

e otnemidneta ed etimil opmet mu ossecorp adac a iubirta rodanolacse O

reludehcS enildaeD

)SA(reludehcs oirtapicetna e reludehcs enildaed :sacitlop saud atnemelpmi 6.2 lenrek od rodanolacse O .otnemidneta ed enildaed mu odubirta oisiuqer adac a ,adinifedni oagretsop rative araP .ocsid od etoebac od otnemacolsed ed aicntsid a raziminim a amrof ed ,sadacifissalc os seisiuqer sa ,ossid mlA .atircse ed searepo sa oaler me edadiroirp meussop arutiel ed searepo sa ,ovitom etse roP .setnaeuqolb-on e sanorcnssa os )ETIRW( ,raunitnoc arap sodad sod atissecen arutiel

atircse ed searepo sa e

ed oarepo a uotucexe euq ossecorp o euq ed oisopus a etsixe euqrop ,setnaeuqolb e sanorcns os )DAER( arutiel ed searepo sa ,xunil oN

reludehcs O/I xuniL

09

:sessalc saud me sadidivid os sedadiroirp sA .0 edadiroirp a rebecer edop daerht atse etnemoS .ametsis on servil sanigp sa rarez rop levsnoper euq ,daerht orez adamahc ,ametsis od laicepse daerht amu a adubirta 0 edadiroirp A .roiam o 13 e ronem o atneserper 0 euq odnes ,13 a 0 ed airav

euq ,edadiroirp ed levn mu odubirta ametsis son daerht adac A .sedadiroirp me odaesab PX/0002 swodniW on sdaerht ed otnemanolacse O

.dnuob UPC so erbos edadiroirp meussop )dnuob O/I( sovitaretni sossecorp so e ,rador a sotpa sossecorp ed salif salpitlm azilitu rodanolacse o PX/0002 swodniW oN

sdaerht ed otnemanolacsE

.edadiroirp aus a e )UPC ad serodartsiger solep odatneserper( oucexe ed otxetnocb ues ,oucexe ed ahlip airprp aus a iussop daerht adaC .iussop ossecorp o euq sdaerht ed edaditnauq a lanoicroporp ossecorp adac arap adacola airmem A .oacilpa ad omsilelarap o rarolpxe a arienam ed ,sadairc os sdaerht sartuo ,sossecorp snugla araP .oucexe arap odagerrac ossecorp o odnauq adairc euq airmirp daerht a ,daerht amu sonem oa iussop ossecorp adaC .swodniW lanoicarepo ametsis on oucexe ed edadinu a euq ,sdaerht ed otnujnoc

mu rop odamrof ossecorp adaC .oucexe aus soirssecen sosrucer so iussop e ,oacilpa amu ed aicntsni amu atneserper odnador ossecorp mU

PX/0002/TN swodniW lanoicarepo ametsis on otnemanolacsE

.odidrep opmet etse ,DAER oarepo artuo atucexe on ossecorp o eS .)kees( setoebac sod otnemanoicisop ed searepo saremni ed aicnrroco a ative arepse atse ,seacilpa satium araP .adidneta res amsem a ,rerroco eS .ossecorp omsem od oisiuqer avon amu rop sm6 arepsE .alif an oisiuqer amixrp a atucexe on rodanolacse o ,atelpmoc es DAER mu odnauQ

;13 a 61 ed sedadiroirp :emit laeR

.51 a 0 ed sedadiroirp :lamroN

19

.PX/0002 swodniW lanoicarepo ametsis od otnemanolacse ed alif a acifilpmexe riuges a arugif A .sm 021 ed opmet ed aitaf a ,revreS 0002 swodniW o araP .)edadivitaretni a recerovaf arap( sm 02 ed opmet ed aitaf a ,lanoisseforp 0002 swodniW ametsis on ,lamron essalc an sossecorp araP .)sossecorp siamed so arap 1 e osses ed redil arap 2 .xe( ossecorp od azerutan ad odnedneped ,edadiroirp ed otnemua mu mbmat mebecer ,oazinorcnis ed searepo spA .)odalcet

arap 6 e ocsid arap1 .xe( ocirfirep od edneped euq ,edadiroirp ed otnemua ed sunb mu mebecer 0/I ed searepo manroter euq sossecorP .oucexe ed opmet me adatsuja edadiroirp aus meussop 51 e 0 ertne edadiroirp moc sossecorP .aretla es on edadiroirp atse 13 e 61 ertne edadiroirp moc sossecorp araP .esab edadiroirp amu ebecer adairc res oa daerht adaC .edadiroirp roiam ed sdaerht sa aicnreferp oret erpmes ,adanoiceles res daerht artuo amu ,otneve mu rop rarepse atissecen daerht a odnauq uo ,opmet o odatogsE .opmet et aitaf amu mebecer )51 a 0( lamron edadiroirp moc sdaerhT .edadiroirp a moc odroca ed sadihlocse os sdaerht sa ,amrof atseD .adanoiceles res 03 edadiroirp moc daerht ariemirp a ,odnitsixe oN .rodassecorp o rahnag arap adihlocse res atse 13 edadiroirp ed daerht artuo odnitsixe ,otnE .otneve mu rop rarepse ta uo ranimret ta ratucexe ,emit laer essalc ad daerht amu ed es-atart omoC .rodassecorp o ahnag alif ad ariemirp a ,13 edadiroirp ed sdaerht odnitsixe ,olpmexe roP .edadiroirp

roiam ed a ehlocse rodanolacse o ,daerht amu a UPC a riubirta araP .daerht atse arap adacificepse res aireved eldi essalc a ,osac etseN .ecnamrofrep an rirefretni on a arienam ed ,sartuo meritsixe on odnauq etnemos ratucexe airedop ametsis on agrac ed otnemarotinom zaf euq daerht amu ,olpmexe roP .ametsis

on sartuo meritsixe on odnauq matucexe etnemos essalc atsen sdaerhT .edadiroirp axiab siam ed a ,eldi adamahc laicepse essalc amu adnia etsixE

29

.ecnamrofrep ed ohnag

mu

me airacilpmi

o ,ehcac me rartnocne es medop euq roiretne oucexe ad sodad ed otnematievorpa arap ,etnemaiverp adatucexe odis aivah lauq on rodassecorp on daerht a ratucexe atnet ametsis o lauq an ,

tfos uo ,odacifcepse

rodassecorp on erpmes edor daerht a euq a agirbo euq aicndneped amu ed aicntsixe a acidni euq ,

drah res edop edadinifa A .ratucexe eved

daerht a lauq on ocifcepse rodassecorp o enifed euq ,edadinifa ed otiecnoc o atnemelpmi 0002 swodniW o ,ossid mlA .serodassecorp sod mu adac me rador arap edadiroirp atla siam ed daerht a anoiceles rodanolacse O .sdaerht sad oucexe an omsilelarap etimrep serodassecorp solpitlm ed aicntsixe a ,otnatne oN .serodassecorp soirv moc uo rodassecorp ocin mu moc aniuqm amu arap edadiroirp ed sievn e sessalc samsem sa moc ,amsem a aruturtse aus e ,rador arap sotnorp sossecorp ed alif amu etnemos etsixE .odagerrac otnemassecorpitlum oa etropus o e adatceted rodassecorp mu ed siam ed aneserp a ,0002 swodniW od lenrek od oalatsni a etnaruD PMS saniuqm me otnemanolacsE

PX/0002 swodniW on sotpa ed atsil ad oatneserpeR eldi 0 1 lamroN 1T 5T 9T 41 51 61

3T

7T 4T

92 03 13 sedadiroirP

laeR opmeT

39

;ocsid od odil res a ocolb o retnoc arap ocolb mu anoiceles

:amrof etniuges ad .lanoicarepo ametsis olep adatart

)setybn ,b& ,f( DAER arutiel ed oarepo amu ,airmem an ajetse


on b mtnoc euq ocolb o euq odnopuS .otnemanezamra ed moc mu .3

aer ed evres euq e ,ocsid ed ocolb mu ed oa laugi ohnamat

adac ,sreffub ed otnujnoc mu meussop sianoicarepo sametsis snuglA

.odamahc otnemidecorp adac euq me seautis saud etiC .oucexe arap ossecorp mu anoiceles euq otnemidecorp od ogidc-oduesp o avercsE )b )c

.oigler od opurretni ad otnematart ed otnemidecorp od ogidc-oduesp o avercsE )a :nibor-dnuor o siamed san e SFCF o odazilitu omtirogla 0 edadiroirp ed alif an euq ,)1 edadiroirp ed alif an men 0 edadiroirp ed alif an muhnen revuoh on es 2 edadiroirp ed ossecorp mu ador etnemos , ossi( seroirefni sa erbos atulosba edadiroirp iussop salif sad amu adac euq odnebaS .soirusu ed samargorp so mador lauq an ,edadiroirp axiab siam ed :2 .sodazilaicepse serodivres mador lauq an airidemretni edadiroirp ed :1 .lanoicarepo ametsis od sossecorp so mador lauq an edadiroirp atla siam ed :0 :gniludehcs salif srt .2

metsixe lauq on odamargorpitlum lanoicarepo ametsis mu eredisnoC ?euqroP ?odahlitrapmoc opmet ed ametsis mu a odauqeda SFCF otnemanolacse ed omtirogla

Exerccios

.1 .

OS o edno ed ,servil socolb ed adaedacne atsil amu etsixe

49

o iunimid es )UPC siam ed matissecen euq( dnuob UPC sossecorp sod salif san arepse ed opmet o odniunimid ,ovitaretni odamargorpitlum lanoicarepo ametsis mu me :oamrifa etniuges a eredisnoC .euqifitsuJ ?)s(odauqeda siam otnemanolacse ed )s(omtirogla )s(o )si(lauq ,)ossecorp mu a odaicossa mu adac( setnerefid serosnes srt rop sodavita ,edadiroirp ed levn omsem ed ,sossecorp srt rop otsopmoc .5

,drah laer
.4

opmet ed lanoicarepo ametsis mu ed sacitsretcarac sa odnaredisnoC .ocirfirep od opurretni ad otnematart ed omtirogla od ogidcoduesp o avercseer ,edadiroirp meussop on sossecorp so euq me ,gniludehcs ed alif acin amu ed aicntsixe a odnopuS )b

.ocirfirep od opurretni a atart euq otnemidecorp od ogidcoduesp o avercsE )a

.adatnemua edadiroirp

;nibor

;)edadiroirp axiab :1 e

;OS olep adacirbaf oisiuqer ad etrap mezaf mbmat oirusu od arutiel ed oarepo an odinifed

:euq odnebaS .aicnrefsnart

;sreffub ed otnujnoc on ,OS olep etnemaiverp odacola ocolb o arap arutiel ed oarepo an odacidni odad o mtnoc

;ocirfirep od seisiuqer ed alif an adaedacne e OS olep adacirbaf

OI ed oisiuqer an odacoloc ocolb essed oeredne o

;oucexe arap ossecorp ovon mu anoiceles OS o

euq ocolb od aicnrefsnart a atucexe ocirfirep od rodalortnoc o

a uonimret euq odnacidni ,opurretni amu areg rodalortnoc o

setyb ed .on o e odanezamra res eved odad o edno oeredne o

edadiroirp atla :0( gniludehcs ed salif saud iussop ametsis o euq

dnuor o salif saud san odazilitu gniludehcs ed omtirogla o euq

aus meussop odatelpmoc OI ues mt euq sossecorp so euq

59

.ossecorp adac ed oucexe ed oidm opmet o e arepse ed opmet o ,oucexe ed opmet o ,tsil ydaer an adagehc ed medro a ,sossecorp ortauq arap ,odnatneserpa atsopser aus euqifitsuJ ?aterroc tse oamrifa atsE . sossecorp sod oucexe ed oidm opmet

Bibliografia

69

.ariter so rodimusnoc ossecorp o edno ed ,reffub on acoloc so e sorietni serolav areg rotudorp ossecorp mu ,olpmexe oN .ralucric reffub moc ,serodimusnoc e serotudorp ed ocisslc amelborp o atnemelpmi acetoilbib a moc e C me odamargorp ,riuges a odatneserpa ,sdaerhtP O

.serotinoM .acitrC oigeR .lanoicidnoC ed soipcnirP acitrC .aut M oigeR .sorofmeS ed .siaicepsE seurtsnI ed .erawdrah soipcnirP

osulcxE

somtiroglA

.aicnrrocnoC

void * consumidor(){ void * produtor(){ int buffer[N], addrprod = 0, addrcons = 0 ; pthread_t th0,th1; #define N 10 #include <pthread.h> #include <stdio.h>

4.1 Princpios de Concorrncia

Processos

4. Sincronizao de

for(i=0; i<20; i++) { while(((addrprod + 1) % N) == addrcons) {} p++; buffer[addrprod] = p ; addrprod= ( addrprod + 1 ) % N ; } } int i, p=50
amargorp

79

rodimusnoc olep adasseca res a oisop amixrp a ,01 rolav o iussop N e ,3 rolav o iussop snocrdda es ,olpmexe roP .arietni osivid ad otser o azilitu euq oarepo ad osu o moc odatnemelpmi ralucric reffub O .rof odnamoc od pool o spa e ,elihw oa setniuges seurtsni sa sadatucexe os ,otnatroP .oslaf ,elihw odnamoc on ,arodimusnoc daerht alep otief etset o ,reffub on sotnemele odnitsixE

.dorprdda atnemercni e p levirav ad rolav o dorprdda oisop an atisoped daerht

a ,oslaf etset o omoC .}{ )snocrdda == )N % )1 + dorprdda(((elihw odnamoc o atucexe ale ,rodassecorp o ahnag arotudorp daerht a odnauQ

.rodassecorp o moc revitse euq me opmet o etnarud elihw on pool me acif daerht atse ,oizav tse reffub o ,otnatrop ,rimusnoc eved arodimusnoc daerht a euq amsem a odad mu racoloc eved arotudorp daerht a lauq an reffub od oisop a euq acifingis euq o ,adacifirev edadlaugi a omoC .}{ )snocrdda == dorprdda(elihw odnamoc o atucexe ale ,rodimusnoc a ajes rodassecorp o rahnag a daerht ariemirp a euq odnopuS

.animret niam daerht a rodimusnoc e rotudorp sdaerht sad etrom a spA .menimret sadairc sdaerht sa euq arepse a ,nioj_daerhtp savitimirp sa moc ,aieuqolb es rodimusnoc

daerht a e rotudorp daerht a rairc spa ,niam daerht a ,amica amargorp oN

} int main(){ } for (i=0; i<20; i++) { while(addrprod == addrcons) {} c = buffer[addrcons] ; printf(" Consumi o valor %d da posio %d \n",c, addrcons) ; addrcons= ( addrcons + 1 ) % N ; } int i, c ; pthread_create(&th0, NULL, produtor, NULL) ; pthread_create(&th1, NULL, consumidor, NULL) ; pthread_join(th0,NULL); pthread_join(th1,NULL);

89

relbmessa ogidc o ,amargorp etsed oalipmoc a spa euq odnaredisnoC .a levirav a mahlitrapmoc 1t e 0t sdaerht sa ,amica amargorp oN

1t ossecorp o e ,levirav 5 rolav o anoicida ot ossecorp O .arietni levirav amu mahlitrapmoc euq , sdaerht saud rop odamrof riuges a amargorp O

mairav secidn so ,sotnemele 01 ed reffub mu me euq evresbO .0 oisop a ,ajes uo ,))01 % )1 + 9(( res oisop amixrp a ,9 rolav o iussop snocrdda eS

int main(){ pthread_create(&tid0, NULL, t0, NULL) ; pthread_create(&tid1, NULL, t1, NULL) ; pthread_join(tid0,NULL); pthread_join(tid1,NULL); printf("O valor de a e: %d\n",a); }
.2 rolav o anoicida .4 ,ajes uo , )01 % )1 +

void * t1(){ long i ;


3( = snocrddA

void * t0(){

long a=0, b, c ;

pthread_t tid0,tid1;

#include <pthread.h> #include <stdio.h>

for (i=0; i<1000000; i++) { a = a + 2; } printf("Encerrei a t1\n"); } for (i=0; i<1000000; i++){ a = a + 5 ; } printf("Encerrei a t0 %d\n",sizeof(int)); } long i ;
.9 a 0 ed

99

ogidC ed acitrC oeS

.56 ,76 res aireved euq

,a levirav ad rolav o ,adidrep iof oazilauta amu ,amrof atseD

.)06( a levirav an odanezamra rodalumuca od rolav o : .56 res a assap rodalumuca od rolav o :

a erots atucexe 0t :5T

5 dda oarepo a atucexe

e )06( odaruatser rodalumuca od rolav o ,rodassecorp o ahnag 0t :4T .)26( a levirav an odanezamra rodalumuca od rolav o :

a erots atucexe 1t 3T
2 dda atucexe 1t :2T

.26 rodalumuca od rolav o : 06 rodalumuca od rolav o :

a daol atucexe e rodassecorp o ahnag 1t :1T


.ovlas

)06( rodalumuca od rolav o :rodassecorp o edrep e

a daol atucexe 0t

:0T

.etnetsisnocni res

a ed rolav o ,searepo ed aicnqes etniuges a moc ,06 a ed rolav o eS


a levirav an rodalumuca od rolav o ranezamra // ; a erots rodalumuca oa 2 rolav o ranoicida // ; 2 dda rodalumuca on a ed rolav o ragerrac // ; a daol

ajes 1t daerht a arap e

a levirav an rodalumuca od rolav o ranezamra // ; a erots rodalumuca oa 5 rolav o ranoicida // ; 5 dda rodalumuca on a ed rolav o ragerrac // ; a daol

ajes

a levirav

a rolav ovon mu ed oiubirta ed oarepo an ,0t daerht a arap odareg

001

.oxiaba odacifilpmexe omoc ,acitrc oes aus an merartne sossecorp sortuo soa ritimrep eved euq ,acitrc oes ad oarebil ed ogidc mu atucexe ,lanif oA .acitrc oes an adartne ed ogidc mu atucexe ossecorp o sodahlitrapmoc sodad rasseca arap ,missA .acitrc oes an adas e adartne ed olocotorp mu ed oazilitu a amelborp o arap oulos ed oledom O

.opmet

;sodahlitrapmoc

acitrc oes ad amelborp od lareg oinifeD

.avisulcxe etnemautum amrof ed otief res eved ogidc ed acitrc oes amu a osseca o euq acifingis otsI .a levirav

an aicntsisnocni amu anoisaco 1t e 0t rop levirav oentlumis osseca O

:amelborp od asuaC

; 2 + a = a

1t ossecorp o arap e

; 5 + a = a

ogidc ed acitrc oes a 0t ossecorp o arap ,amica olpmexe oN .olelarap me odatucexe res ed edop on ,otnatrop matucexe ,euq e ,sodahlitrapmoc so lauq on sodad ogidc me ed oacifidom mu

searepo

sossecorp

ohcert

;1 > N ,sossecorp N moc ametsis

;oirprp ogidc ues atucexe ossecorp adac

;opit reuqlauq ed ,sievirav sodad mahlitrapmoc sossecorp so

sodad so mazilauta edno ,s

CS

iussop ossecorp adac

on avisulcxe etnemautum amrof ed res eved CS amu ed oucexe a

101

sossecorp 2 arap WS rop seuloS

.acitrc oes ad amelborp o revloser arap sodazilitu autm osulcxe ed somtirogla so sodatneserpa ores riuges A

euq raredisnoc es-eved ,ossid mlA

.sacitrc sees savitcepser saus ed meas e martne ,etnemaditeper ,sossecorp sortuo otnauqne ,acitrc oes an rartne arap odnarepse etnemadinifedni racif edop on ossecorp mu :adatimil arepse )c

.acitrc oes a odnasu tse ossecorp ortuo muhnen es acitrc oes aus an rartne ossecorp mu a oditimrep res eved :ossergorp )b

;acitrc oes an rartne oditimrep zev rop ossecorp mu etnemos :autm osulcxe )a

:sadicedebo res matissecen seidnoc setniuges sa ,acitrc oes ad amelborp o revloser araP

acitrc oes ad amelborp od oulos arap sotisiuqeR

oes an ertne ossecorp ortuo euq etimrep noitces-tixe a e acitrc oes aus a etucexe zev rop ossecorp 1 etnemos euq ritnarag eved noitces-yrtne A

noitces-tixe

acitrc-oes-ogidc
noitces-yrtne

;sadanimretedni sedadicolev meussop sossecorp so

sod avitaler edadicolev a erbos seisopus

4.2 Algoritmos de Excluso Mtua


.sossecorp rezaf eved es on .acitrc

201

sdaerhtp moc odamargorp ,1 omtirogla o odatneserpa res riuges A .0 od zev a siop rartne redop on 1 o

,etnemavon rartne ajesed 1 ossecorp o e ,acitrc oes an rartne adnia ajesed on 0 ossecorp o eS .0 ossecorp o arap zev a assap ,atucexe 1 ossecorp o es ,missA .adavresbo on ossergorp ed oidnoc a euq acifingis ossI .etnaid

rop missa e ,0 o sioped ,1 o sioped ,0 ossecorp o ratucexe eved oriemirp ,0 ONRUT ed laicini rolav o es ,olpmexe roP .oucexe an aicnnretla amu reuqer siop ,ogidc ed acitrc oes ad amelborp o evloser on omtirogla etsE

.1 ossecorp o rartne eved ,1 rof rolav o es ,0 ossecorp od zev a ,0 rolav o revit onrut eS .acitrc oes an rartne edop ossecorp lauq acidni euq ,ONRUT ,arietni levirav amu mahlitrapmoc sossecorp sO 1 omtirogla

} void * p1 (){ void * p0 (){ int turn = 0 ; int shared ; pthread_t tid0,tid1; #include <pthread.h> TURNO: integer; % varivel compartilhada; 0 ou 1 EU, OUTRO: integer; % constantes locais, com valores opostos (0,1 e 1,0) repeat while (TURNO !=EU) do {}; % mutexbegin cdigo-da-seo-crtica; TURNO := OUTRO % mutexend resto-do-cdigo; until false; var for(i=0; i<10; i++) { while(turn != 0 ) {} //entra se turn = 0 shared =shared + 50 ; printf("Thread1: INCREMENTEI \n"); turn = 1 ; } int i ;

301

:oucexe ed aicnqes etniuges a odnaredisnoC .acitrc oes an opmet omsem oa rartne medop ossecorp siod so siop ,acitrc oes ad amelborp o evloser on amica omtirogla O

aus a ratucexe edop etnemos ossecorp mU .acitrc oes an tse i ossecorp o euq acifingis oriedadrev ]i[galf eS .galf ,seisop saud ed naeloob opit od rotev mu rop adutitsbus ONRUT levirav a ,riuges a omtirogla oN .rartne ajesed omsem o es rebas mes ,ossecorp ortuo o arap zev a assap acitrc oes ad odnias tse euq ossecorp O .ossergorp ed oidnoc a zafsitas

on euq o ,oucexe ed aicnnretla a omtirogla oriemirp od amelborp O 2 omtiroglA

// algoritmo 2 var var flag[0..1] of boolean // varivel compartilhada, inicializada com false repeat while flag[j] do {}; % mutexbegin flag[i] := true ; cdigo-da-seo-crtica flag[i] := false % mutexend resto-do-cdigo; until false;
.oslaf rof ossecorp ortuo oa etnednopserroc galf ed rolav o es acitrc oes sossecorp 2 arap WS rop seuloS

main(){ pthread_create(&tid0, NULL, p0, NULL) ; pthread_create(&tid1, NULL, p1, NULL) ; pthread_join(tid0,NULL); pthread_join(tid1,NULL); } } int i ; for (i=0; i<10; i++) { while(turn != 1 ) {} //entra se turn = 1 printf("Thread2: SHARED: %d \n",shared); turn = 0 ; }

401

]0[galf ourtsni a atucexe e rodassecorp o ahnag 0p ,acitrc oes ad ortned

rodassecorp o edrep 1p eS .acitrc oes an artne e ;eurt = ]1[galf oarepo

#include <pthread.h> pthread_t tid0,tid1; int shared = 0 ; int flag [2]; void * p0(){ int i ; for(i=0; i<1000000; i++) { while(flag [1] == 1 ) {} /* entra se flag [1] = 0 */ flag[0] = 1 ; shared =shared + 5 ; flag [0] = 0 ; } } void * p1(){ int i ; for (i=0; i<1000000; i++) { while(flag [0] == 1 ) {} /* entra se flag [0] = 0 */ flag [1] = 1 ; shared = shared + 2 ; flag [1] = 0 ; } } main(){ flag [0] = 0 ; flag [1] = 0 ; pthread_create(&tid0, NULL, p0, NULL) ; pthread_create(&tid1, NULL, p1, NULL) ; pthread_join(tid0,NULL); pthread_join(tid1,NULL); printf("O valor final de shared e:%d\n", shared); }

a ratucexe ;eslaf ]0[galf ed rolav o artnocne e rodassecorp o ahnag 1p :1T

oes an otse sossecorp siod so ,ogoL .acitrc oes a arap iav e eurt =

o edrep e eslaf ]1[galf ed rolav o artnocne e rodassecorp o ahnag 0p :oT .autum osulcxe atnemelpmi on ;eurt = ]i[galf oarepo a ratucexe ed setna rodassecorp :sdaerhtp moc odamargorp 2 omtiroglA omtirogla o otnatrop e ,acitrc

501

sdaerhtp moc odamargorp 3 omtiroglA

.onrete pool mu me macif 1P e 0P ,otnatroP .oriedadrev rolav o meussop ]1[galf otnauq ]0[galf otnat ,arogA

;eurt = ]1[galf zaf 1 P :1T

rodassecorp o edrep e ;eurt = ]0[galf zaf 0P :0T

es siop ossergorp ed oidnoc a zafsitas on )b

an rartne edop zev rop ossecorp 1 etnemos siop ,autm osulcxe a zafsitas )a

:sedadeirporp setniuges sa iussop amica omtirogla O

acitrc oes an artne e pool od ias ele ,revitse on ossecorp ortuo o eS .acitrc oes an tse ossecorp ortuo o euq acidni euq oisop a atset etnemroiretsop e acitrc oes an rartne ajesed omsem o euq racidni arap galf ed rolav o acifidom oriemirp ossecorp o ,riuges a omtirogla oN .on uo acitrc oes an tse omsem o es acidni euq ,galf levirav ad rolav o radum ed setna rodassecorp o redrep edop ossecorp o euq 2 omtirogla od amelborp O 3 omtiroglA

sossecorp 2 arap WS rop seuloS

pthread_t tid0,tid1; #include <pthread.h>


;acitrc oes

// algoritmo 3 var var flag[0..1] // varivel compartilhada, inicializada com false repeat flag[i] := true ; while flag[j] do skip; // mutexbegin cdigo-da-seo-crtica; flag[i] := false // mutexend resto-do-cdigo; until false;

int shared = 0; int flag [2]; void * p0(){ int i ; for(i=0; i<1000000; i++) { flag[0] = 1 ; printf("Thread0%d\n", shared) ; while(flag [1] == 1 ) {} /* entra se flag [1] = 0 */ shared =shared + 5 ; flag [0] = 0 ; } } void * p1(){ int i ; for (i=0; i<1000000; i++) { flag [1] = 1 ; printf("Thread1%d\n", shared) ; while(flag [0] == 1 ) {} /* entra se flag [0] [0] = 0 */ shared = shared + 2 ; flag [1] = 0 ; } } int main(){ flag [0] = 0 ; flag [1] = 0 ; pthread_create(&tid0, NULL, p0, NULL) ; pthread_create(&tid1, NULL, p1, NULL) ; pthread_join(tid0,NULL); pthread_join(tid1,NULL); printf("O valor final de shared e:%d\n", shared); }

var flag[0..1] of boolean; com false var turn of integer; repeat

// varivel compartilhada, inicializada

flag[i] := true ; turn := j ; loop exit when not(flag[j]) or turn = i);

a iof ,2691 me rekkeD .T

autm osulcxe ad amelborp o arap adatneserpa aterroc oulos ariemirp

601

ocitmetam olep odivlovnesed ,riuges a omtirogla O

sossecorp 2 arap WS rop seuloS sossecorp siod ertne

// mutexbegin

701

amu azilitU .sossecorp siod ertne autm osulcxe ad amelborp o arap aterroc oulos amu atnemelpmi ,1891 me odatneserpa ,nosreteP ed omtirogla O

sossecorp 2 arap WS rop seuloS

.acitrc oes an artne etnatisiuqer ossecorp o otnatrop ,0 rolav o mtnoc ossecorp ortuo oa etnednopserroc galf rotev on

oisop a )c( osac oN .nrut levirav a odnates ,ortuo oa ecerovaf acitrc oes ad ias ossecorp o euq erpmes euqrop rerroco ed levssopmi mbmat )b( osac O .ossecorp mu ecerovaf erpmes nrut levirav a euqrop levssopmi )a( osac O .rartne essajesed on ossecorp ortuo o )c( ,etnemlanif ,e acitrc oes ad essas e essartne etnemaditeper ossecorp ortuo o es )b( ,pool on essevitse mbmat ossecorp ortuo )a( o es levssop aires etnemos ossI .adartne ed oidnoc a odnatset ,pool on etnemanrete odaeuqolb essacif etnatisiuqer ossecorp o es adaloiv aires etnemos adatimil arepse ed oidnoc A

.acitrc oes aus a ratucexe ri etnatisiuqer ossecorp o ossi moC .acitrc oes an tse on omsem o euq odnacidni ,0 rolav o moc ,galf rotev on ,ossecorp ortuo oa etnerefer oisop a rartnocne rartne ajesed euq ossecorp o euqrop atiefsitas ossergorp ed oidnoc A

.acitrc oes an rartne airedop mu etnemos euq odnitnarag e ossecorp ocin mu a odnecerovaf ,)1 uo 0( rolav mu ret edop etnemos nrut levirav a omoc ,otnatne oN .)1( oriedadrev rolav o messevit ]1[galf e ]0[galf euq airatissecen euq ,acitrc oes an messartne sossecorp siod so es adaloiv aires autm osulcxe A

.adatimil arepse ed e ossergorp ,autm osulcxe ed sedadeirporp sa zafsitas omtirogla O

until false; flag[i] := false; cdigo-da-seo-crtica resto-do-cdigo; // mutexend

801

.sdaerhtp moc odamargorp nosreteP ed omtiroglA

.adatimil arepse ed oidnoc a ,otnatrop ,odnitnarag ,acitrc oes a etucexe 0p euq zev amu rarepse etnemos 1p euq etnarag euq o o arap zev a d ,nrut levirav a odnates ,)1p .xe( ossecorp ortuo

)0p .xe( acitrc oes ad odnias ossecorp o :adatimil arepsE

.rartne reziuq on ortuo o es acitrc oes an artne ossecorp o :ossergorP

.autm osulcxe etnarag euq o ,nrut levirav alep odacidni euq o ,zev aus a rof es uo rartne reziuq on ortuo o es acitrc oes an artne etnemos ossecorp mu :autm osulcxE

.adatimil arepse ed e ossergorp ed ,autm osulcxe ed sedadeirporp sa zafsitas nosreteP ed omtirogla O

.elihw odnamoc on assap on ,osac etseN .j= nrut e eurt = ]j[galf es acitrc oes an artne on i ossecorp O .acitrc oes an tse ossecorp o es acidni euq ,galf ,seisop saud ed onaeloob rotev mu e ,acitrc oes an rartne reved ossecorp lauq acidni euq ,nrut levirav

void * p0(){ int turn ; int shared ; int flag [2]; pthread_t tid0,tid1; #include <pthread.h> var flag[0..1] of boolean; //compartilhada, inicializada com false var turn of integer; repeat flag[i] := true ; turn := j ; while flag[j] and turn = j do nop; // mutexbegin cdigo-da-seo-crtica; flag[i] := false; // mutexend resto-do-cdigo; until false;

int i ;

901

.aicnreferp ret oremn ronem o moc ossecorp O .ahlocse arap odasu sossecorp od oremn o ,osac etseN .rolav omsem o retbo edop ossecorp mu ed siam ,etnemetnerrocnoc atief tekcit od onetbo a omoC .acitrc oes an rartne arap aicnreferp tekcit mu retbo asicerp

met rolav ronem ed tekcit o moc ossecorp o e

ossecorp adac ,acitrc oes an rartne arap ,tropmaL ed omtirogla oN

.sossecorp

n arap acitrc oes ad amelborp o anoiculos euq ,odatneserpa ,tropmaL .sossecorp siod

riuges a ,airadap ad omtirogla o uoirc ,4791 me

ertne autm osulcxe ad amelborp o arap aterroc oulos amu matnemelpmi ,etnemroiretna sodatneserpa ,nosreteP e rekkeD ed somtirogla sO

sossecorp N arap erawtfos rop seuloS

int main() { flag [0] = 0 ; flag [1] = 0 ; pthread_create(&tid0, NULL, p0, NULL) ; pthread_create(&tid1, NULL, p1, NULL) ; pthread_join(tid0,NULL); pthread_join(tid1,NULL); printf("O valor final de shared e:%d\n", shared); } int i ; for (i=0;i<10000; i++) { flag[1] = 1 ; turn = 0 ; while(flag [0]==1 && turn==0 ){}/*entra se flag[0]=0 ou turn =1*/ shared =shared + 2 ; flag [1] = 0 ; } } } void * p1(){ for(i=0; i<10000; i++) { flag[0] = 1 ; turn = 1 ; while(flag [1]==1 && turn==1 ){}/*entra se flag[1]=0 ou turn=0 */ shared =shared + 5 ; flag [0] = 0 ; }

011

acitrc oes an rartne ajesed euq o ,

,sutats rotev on ,azilanis p ossecorp

pooL o spa sodnamoc srt soriemirp son ,amica ogidc-oduesp oN

.acitrc oes an rartne ajesed omsem o odnauq ,tekcit od rolav o uo ,acitrc oes an rartne ajesed on omsem o odnauq euq

0 ,i ossecorp o arap ,mtnoc

,tekcit e ,sossecorp so sodot arap eslaf moc odazilaicini ,tekcit mu rarit ,sutats ,serotev siod iussop omirogla O
cdigo no crtico End_loop

ajesed euq azilanis ossecorp o lauq on

airadap ad omtirogla //

;oremn mu ebecer etneilc airadap an rartne ed setna

;odivres oremn ronem moc etneilc

sod rodacifitnedi o osac etsen ,oremn omsem rebecer medop setneilc

Loop { status[i] = true; ticket[i] = 1 + (max(ticket[0], ticket[1], .. , ticket[n-1]); status[i] = false ; for (j=0; j<n-1; j++) { while (status[j]) {} // comando vazio while ( (ticket[j] !=0 && (ticket[j],j < ticket[i], i) {}//Comando vazio }

.riuges a odatneserpa tropmaL ed omtirogla od ogidc-oduesp O

status[i] = false; para i = 0 ... i = n-1 ; ticket[i]= 0 ; para i = 0 ... i = n-1 ;

;ahlocse a arap odasu sossecorp

.aicnreferp met ronem

// estrutura do processo Pi //inicialmente

// variveis compartilhadas var status: array [0..n-1] of boolean; var ticket: array [0..n-1] of integer;

// n = nmero de processos

ticket [i] = 0 ; // libera seo crtica Seo crtica de cdigo


airadap ad omtirogla // oremn

111

.sdaerht ortauq moc ,sdaerhtp moc odamargorp tropmaL ed omtiroglA

.acitrc oes a metucexe sossecorp 1 n euq arepse

i ossecorp o e ,)osac roip( ,tekcit ed rolav roiam o ragep i ossecorp o ,acitrc


oes a rasu merajesed sossecorp siamed so sodot eS :adatimil arepsE

.acitrc oes an artne

sutats(

acitrc oes a odnasu tse ossecorp ortuo muhnen es :ossergorP

oremn ronem ed o ,tekcit ed oremn omsem o merussop sossecorp siam uo siod ed osac on uo ,tekcit ronem o moc ossecorp o etnemos :autm osulcxE

ed seidnoc sa zafsitas omtirogla etsE .ossecorp ovon mu ed adartne a ritimrep euq rop atief acitrc oes ad oarebil A

ronem ed o

p ossecorp od tekcit o uo acitrc oes an rartne reuq on j p ossecorp o

,j sossecorp so sodot arap ,es acitrc oes en rartne etnemos euq etnarag ,

elihw odnamoc odnuges O .tekcit mu odnagep tse jp ossecorp p ossecorp o ,elihw odnamoc oriemirp on ,riuges A

o otnauqne pool me acif

olep oditbo j rolav roiam o

int max_number () { int i, maior ; maior = 0 ; for (i=0; i<N; i++){ if (ticket[i] > maior) maior = ticket [i] ; } return (maior + 1) ; } void mutex_begin (int i ) { int j ; status[i] = TRUE;
.adatimil arepse ed e ossergorp ed ,autm osulcxe .1 +

int turn ; int shared ; int status [N] , ticket [N], proc_id [N] ;
.acitrc oes an artne rodacifitnedi ed

acitrc oes an rartne mereuq euq serap sues


res euq ,tekcit mu ariter e )

pthread_t tid0,tid1, tid2, tid3;

i ossecorp o ,)j o odot arap eslaf=]j[

#include <pthread.h> #define N 4 #define TRUE 1 #define FALSE 0 ticket [i] = 0,

.rolav

; eurt = ]i[sutats(

ticket[i] = max_number () ; status[i] = FALSE ; for (j=0; j<n-1; j++) { while (status[j]) {} // comando vazio while ( (ticket[j] !=0 && (ticket[j] < ticket[i]) || (ticket[j] !=0 && (ticket[j] == ticket[i]) && (proc_id[j] < proc_id[i] )) {}//Comando vazio } } void mutex_end (int i ) { ticket [i] = 0 ; } void * p0(){ int my_number = 0 ; int i ; proc_id[my_number] = tid0 ; for(i=0; i<1000000; i++) { mutex_begin (my_number) ; shared =shared + 1 ; mutex_end (my_number) ; } } void * p1(){ int my_number = 1 ; int i ; proc_id[my_number] = tid1 ; for(i=0; i<1000000; i++) { mutex_begin (my_number) ; shared =shared + 1 ; mutex_end (my_number) ; } } void * p2(){ int my_number = 2 ; int i ; proc_id[my_number] = tid2 ; for(i=0; i<1000000; i++) { mutex_begin (my_number) ; shared =shared + 5 ; mutex_end (my_number) ; } } void * p3(){ int my_number = 3 ; int i ; proc_id[my_number] = tid3 ; for(i=0; i<1000000; i++) { mutex_begin (my_number) ; shared =shared + 1 ;

211

311

;orofmes on sodaeuqolb sossecorp ed alif amu arap rodatnopa mu

:sorofmes sod sacitsretcaraC .5691 me artskjiD rop sodivlovnesed ,sorofmes so os ,adapuco arepse ad amelborp o animile euq e ,acirneg siam oulos amU sorofmeS

.ametsis od ohnepmesed o etnemaires retemorpmoc edop aromed atse ,sednarg sacitrc sees mE .adaidrepsed res rodassecorp od opmet ed aitaf aus a adot ,aslaf amsem a eS .adartne ed oidnoc a ratset matissecen acitrc oes aus a ratucexe majesed euq sossecorp sO .adapuco arepse ed o ajes lauq ,amelborp evarg mu mtnoc sadatneserpa seulos sA

Condicional, Regio Crtica e Monitores

4.3 Semforos, Instrues Especiais, Regio Crtica

int main() { int i ;

pthread_join(tid0,NULL); pthread_join(tid1,NULL); pthread_join(tid2,NULL); pthread_join(tid3,NULL); printf("O valor final de shared e:%d\n", shared);

pthread_create(&tid0, pthread_create(&tid1, ptrhead_create(&tid2, pthread_create(&tid3,

for (i=0; i<N; i++) { status[i] = FALSE ; ticket [i] = 0 ; }

e rodatnoc mu rop adamrof ,sodad ed aruturtse amu

s orofmes mU

mutex_end (my_number) ;

NULL, NULL, NULL, NULL,

p0, p1, p2, p3,

NULL) NULL) NULL) NULL)

; ; ; ;

411

{ ) 0 < eulav.s( fi

; 1 - eulav.s = eulav.s :)s(P

:etniuges a s orofmes on P oarepo A .orofmes on odaeuqolb ossecorp omitl o arap rodatnopa mu e orofmes on odaeuqolb ossecorp oriemirp o arap rodatnopa mu ,orofmes od rolav o ,orofmes od rodacifitnedi o mtnoc euq sodad ed aruturtse amu ed osu o moc atief sorofmes ed oatnemelpmi A

; eslaf litnu

acitrc on oes

)xetum(V

acitrc oes

; )xetum( P

taeper

:etniuges a ,iP ossecorp adac arap ,sorofmes sod oazilitu ed aruturtse A

.1 rolav o moc sodazilaicini odnauq

;airrtibra medro amu me ,etnemlaicneqes sadatucexe res ori searepo sasse

;odadroca orofmes od alif ad oriemirp o ,sodaeuqolb

;0 orofmes

;)V e P( sacimta searepo saud rop odasseca res edop etnemoS

od rolav o es atucexe a euq ossecorp o aieuqolb P oarepo A

sossecorp odnitsixE .orofmes od rolav o atnemercni V oarepo A

;etnemacimota sadatucexe os orofmes od rolav on seacifidom sA

,)s(V uo )s(P ratucexe

,etnemaenatlumis ,matnet sossecorp siod eS

,sossecorp

n moc autm osulcxe arap sodasu res medop sorofmeS

511

.odatnemercni orofmes od rolav o ,oirrtnoc osaC .odadroca omsem o ,odaeuqolb ossecorp mu etsixe eS .orofmes od alif a acifirev V oarepo A .)oucexe a aunitnoc( odaeuqolb acif on ossecorp o e odatnemerced ,0 euq roiam odneS .odaeuqolb a c if ossecorp o e 0 ecenamrep rolav

o ,0 omsem od rolav o eS .orofmes od rolav o acifirev P oarepo A .1 e 0 ed setnerefid serolav rimussa edop )rodatnoc orofmes( oirnib on orofmes

mU .orofmes od rolav oa 1 odubirta oirrtnoc osac ,odadroca oriemirp o ,odaeuqolb ossecorp mugla etsixe eS .orofmes od alif a acifirev V oarepo A .odaeuqolb acif P oarepo a atucexe euq ossecorp o ,0 orofmes od rolav o eS .1 e 0 serolav so emussa etnemos odnauq oirnib orofmes mU

)serodatnoc( soirnib on e soirniB sorofmeS

/*p ossecorp o adroca*/ ; )p(puekaw

l.s atsil ad

ossecorp o revomer

{ ) 0= < eulav.s( fi

; 1 + eulav.s = eulav.s :)s(V

.odarebil alif ad oriemirp o ,orofmes on sodaeuqolb sossecorp meritsixe eS .ogidc ed acitrc oes a rarebil arap ossecorp olep adatucexe )s(V oarepo A

.acitrc oes ad ortned oucexe a aunitnoc ossecorp o ,oirrtnoc osaC .odaeuqolb acif ossecorp o ,orez euq ronem uo orez orofmes od rolav o eS .acitrc oes an rartne ajesed euq ossecorp olep adatucexe oarepo atsE

/*p ossecorp o aieuqolb*/

; )p(kcolb

me sodaeuqolb sossecorp ed atsil an ossecorp o ranoicida

611

!!! orrE // { ) 0 =! )1 ,0 ,s&(tini_mes ( fi ;s t_mes >h.erohpames< edulcni#

:olpmexE

.adidecus meb oucexe euq acidni 0 rof adamahc ad onroter ed rolav o eS

.orofmes od laicini rolav o : ;oirrtnoc osac 0 ed etnerefid e ossecorp ortuo me sdaerht moc odahlitrapmoc on orofmes o euq acidni 0 :

eulav

derahsp mes

;orofmes levirav ad oeredne o :

,edno

;)eulav tni dengisnu ,derahsp tni ,mes* t_mes(tini_mes tni

avitimirp a moc atief orofmes od laicini rolav od oiubirta a ,odaralced odis ret spA

; s t_mes >h.erohpames< edulcni#

:amrof etniuges ad adazilaer

s orofmes mu ed oaralced A .t_mes orofmes opit od oinifed a mtnoc


>

h.erohpames/sys< acetoilbib A

.)V e P ,oazilaicini arap searepo(

sorofmes ed oazilitu a e oazilaicini a metimrep euq savitimirp mtnoc e soirnib on sorofmes ed oinifed a iulcni sdaerhtp acetoilbib A

sdaerhtp acetoilbib an sorofmeS

711

.emirpmi e ariter so arodimusnoc daerht a edno ed ,reffub on sorietni serolav atisoped )arotudorp a( daerht amU .oisop 1 ed reffub mu a sdaerht saud ed osseca o razinorcnis arap sorofmes azilitu euq C me otircse amargorp mu atneserpa riuges a olpmexe O

acitrc on oes ;)s&(tsop_mes acitrc oes ;)s&(tiaw_mes


{ )( i P

:odazilaicini e odinifed s orofmes o odnopus ,iP ossecorp o arap ,olpmexE

;)0s* t_mes(tsop_mes tni ;)0s* t_mes(tiaw_mes tni


.riuges a sadartsom omoc ,tsop_mes e tiaw_mes ,etnemavitcepser ,os orofmes

mu me V e P searepo sA .avitimirp ad oucexe an orre acidni orez ed etnerefid onroter ed rolav O .sossecorp sortuo me sdaerht moc odahlitrapmoc on ,1 rolav o moc

s orofmes od rolav o azilaicini tini_mes oarepo A

void * produtor(){ int buffer; #include <pthread.h> #include <semaphore.h> pthread_t tid1,tid2; sem_t s0, s1 ;

int i ; for(i=0; i<100; i++) { sem_wait(&s0) ;

811

:os sodasu sorofmes sO .oamrofni ed meti mu ed otnemanezamra ed edadicapac met otnemele adaC .sotnemele n ed ralucric reffub mu mahlitrapmoc ,rodimusnoc mu e rotudorp mu ,sossecorp sioD .arutaretil ad ocisslc ,odatimil reffub od amelborp o odatneserpa res riuges A

oazinorcnis ed socisslc samelborP

oarepo a etucexe rodimusnoc o euq ta 0s orofmes on odaeuqolb racif ,zev aus rop ,rotudorp O oarepo a ratucexe e reffub

on otnemele mu odatisoped ret rotudorp o spa odaeuqolbsed res e ,1s orofmes on odaeuqolb racif ri ,rodassecorp o rahnag rodimusnoc ossecorp o eS .0 moc 1s o e 1 moc odazilaicini 0s orofmes o ,amica amargorp oN

sem_post(&s0

otnemele o rariter rodimusnoc o euq erpmes rerroco euq o

,)

int main(){

} } void * consumidor(){ int i, k ; for(i=0; i<100; i++) { sem_wait(&s1) ; k = buffer ; sem_post(&s0) ; printf("Valor consumido: %d\n", k) ; } }

pthread_create(&tid1, NULL, produtor, NULL); pthread_create(&tid2, NULL, consumidor, NULL) pthread_join(tid1,NULL); pthread_join (tid2,NULL);

sem_init(&s0, 0, 1) ; sem_init(&s1, 0, 0) ;

buffer = i ; sem_post(&s1) ;

o
.reffub od

;autm osulcxe arap :xetum

;soizav sreffub ed oremn od rodatnoc :ytpme

sem_post(&s1).

911

a odatneserpa amargorp od ogidc O .1 moc xetum e 0 moc lluf ,)reffub od

#include <pthread.h> #include <semaphore.h> pthread_t tid1,tid2; sem_t full, empty, mutex ; #define N 10 int buffer[N]; int i=0, j=0 ; // Produtor produz na posio i e consumidor consome da //posio j

void * produtor(){

for(;;) { sem_wait(&empty) ; sem_wait(&mutex) ; buffer[i] = 50 ; i = ( i + 1 ) % N ; sem_post(&mutex) ; sem_post(&full) ; } } void * consumidor(){ int j, c ; for (;;) { sem_wait(&full); sem_wait(&mutex); c = buffer[j] ; j = ( j + 1 ) % N ; sem_post(&mutex); sem_post(&empty); } } int main(){ sem_init(&mutex, 0, 1) ; sem_init(&full, 0, 0) ; sem_init(&empty, 0, 10) ; pthread_create(&tid1, NULL, produtor, NULL);

sotnemele ed oremn( N moc odazilaicini res eved ytpme orofmes O

.soiehc sreffub ed oremn od rodatnoc :lluf

.sdaerhtp e C moc odamargorp rodimusnoC/rotudorP

.riuges

021

a adacoloc aires

)(rasnep adamahc a spA .1 rolav o moc odazilaicini

,oirnib orofmes mu rasu res airedop selpmis oulos amU .atierid ad ofrag od arepse a sodaeuqolb mairacif sodot ,adreuqse ad ofrag ues o eugep ossecorp adac euq es-odnanigamI .kcoldaed a avel etnemaralc oulos atsE } } ; )1 + lif( ofrag_ragral ; )lif( ofrag_ragral ; )( remoc ; )1 + lif( ofrag_ragep ; )lif( ofrag_ragep ; )(rasnep { ) ;;(rof { )lif tni( ofosolif * diov sofoslif sossecorp solep odatucexe ogidc //

:etniuges a laivirt oulos amU

.zev adac ed ofoslif ,mu

rop odasu res edop etnemos ofrag mu sam ,asrev-eviv uo ,atierid ad o sioped e adreuqse ad ofrag o oriemirp ragep ridiced ,etnemairartibra ,edop ofoslif adaC .sofrag siod ed asicerp ,ossi arap ,e remoc e rasnep me etsisnoc

ofoslif mu ed adiv A .iteugapse ed otarp mu met ofoslif adaC .sofrag siod adac ertne ofoslif mu e sofoslif siod adac ertne ofrag mu etsixE .adnoder asem amu ed atlov me sodatnes otse sofoslif ocnic ed opurg mU .adinifedni oagretsop uo kcoldaed ranoisaco odnedop ,zev adad ed ossecorp mu rop odasu res odnedop mu adac ,sosrucer ed otinif otnujnoc mu mahlitrapmoc euq sossecorp ed otinif otnujnoc mu ed etsisnoC .sossecorp ertne sosrucer ed oaacola a etnererefer e 5691 me artskjiD .W .E rop otsoporp iof amelborp etsE sofoslif sod ratnaj od amelborP

} pthread_create(&tid2, NULL, consumidor, NULL) pthread_join(tid1,NULL); pthread_join (tid2,NULL);

121

on sohniziv sues so es odnemoc odatse o arap rassap edop etnemos ofoslif mu ,oulos atseN .osu me essevitse ofrag o es odaeuqolb racif airedop ofrag mu ririuqda odnatnet emof moc ofoslif mu ,lauq on sorofmes ed rotev mu e )odnasnep ,odnemoc ,emof moc( sossecorp .sofoslif

ed reuqlauq oremn mu arap omsilelarap ed omixm o etimrep e artskjiD ed oulos an adaesab adatneserpa res euq oulos adnuges A .levnopsid tse ofrag o euq odnacidni ,1 rolav o moc sodazilaicini ,ofrag mu odnatneserper mu adac ,sorofmes ed rotev mu odasu .ogidc omsem o matucexe on sofoslif so , otsi

,acirtmis on ,aterroc arobme ,oulos atsE .atierid ad ofrag o ,siuza so ,adreuqse ad ofrag o ragep matnet oriemirp sohlemrev sofoslif sO

.)luza/ohlemrev( sopurg siod me sodacifissalc ores sofoslif so ,oulos ariemirp aN .]0002 nuabmenaT .S .A[ nuabmenaT .S .A rop otircse ogidc on e ]1791 ,.W .E ,artskjiD[ artskjiD .W .E rop sadatneserpa seulos san sadaesab ,amelborp etse arap seulos saud sadatneserpa ores riuges A

adaC .)sofoslif ed oremn o n( stekcit n moc axiac amu etsixe ;sofoslif soa sofrag ed oiubirta a alortnoc euq lartnec rotinom mu etsixe ;oriemirp atierid ad ofrag o ragep matnet siuza so ,oriemirp adreuqse ad ofrag o ragep matnet sohlemrev sO .luza e ohlemrev ,sodiroloc os sofoslif so

etnecajda ofrag o ragep atnet ofoslif adac e sodaremun os sofrag so :amelborp o arap seulos saremni metsixE

ofoslif mu etnemos euq etimrep siop ,airtafsitas on oulos atse ,otnatne oN .V oarepo ac

//Soluo para o problema do jantar dos filsofos na qual os filsofos // so classificados em vermelhos e azuis
.odnemoc merevitse sod etnerroc odatse o retnam arap rotev mu azilitu alE ;sofrag so ragep ed setna tekcit o retbo asicerp ofoslif )d )c )b ;oriemirp roiam oremn ed )a .amoc zev rop

)1 + lif( ofrag_ragral adamahc a spa e P oarepo

#include <pthread.h> #include <semaphore.h> # # # # define define define define N PENSANDO COM_FOME COMENDO 5 0 1 2

pthread_t tid[N]; sem_t garfos[N]; void pensar ( int fil) { int t ; t = rand()%N ; printf("O filosofo %d vai pensar %d segundos\n", fil, t) ; sleep (t) ; } void comer (int fil) { printf("Vai comer o filosofo %d\n", fil) ; sleep (2) ; }

void pegar_garfos(int fil){ if ( fil % 2 == 0 ) { //Vermelhos: pegar o garfo da esquerda e aps o da direita sem_wait(&garfos[fil]) ; sem_wait(&garfos[(fil+1) % N] ); } else { // Azuis: pegar o garfo da direita e aps o da esquerda sem_wait(&garfos[(fil+1) % N] ); sem_wait(&garfos[fil]) ; } } void depositar_garfos(int fil){ sem_post(&garfos[fil]) ; sem_post(&garfos[(fil+1) % N] ); } void * filosofos (void * fil) { int i ; for (i=0;i<10; i++) { pensar((int)fil) ; pegar_garfos((int)fil) ; comer((int)fil) ; depositar_garfos((int)fil) ; } }

221

int main(){ int i ;

for (i=0; i<N;i++) sem_init ( &garfos[i], 0, 1); for (i=0; i<N;i++){ pthread_create(&tid[i], NULL, filosofos, (void *)i); } for (i=0; i<N;i++){ pthread_join(tid[i],NULL); }
}

// Problema do jantar dos filsofos que para //um nmero qualquer de filsofos #include <pthread.h> #include <semaphore.h> # # # # define define define define N PENSANDO COM_FOME COMENDO 5 0 1 2

permite paralelismo

pthread_t tid[N]; sem_t s[N], mutex ; int estado [N] ; void pensar ( int fil) { int t ; t = rand()%N ; printf("O filosofo %d vai pensar %d segundos\n", fil, t) ; sleep (t) ; } void comer (int fil) { printf("Vai comer o filosofo %d\n", fil) ; sleep (2) ; } void teste (int fil) { if(estado[fil]==COM_FOME && estado[(fil+N-1)%N]!=COMENDO && estado[(fil+1)%N] != COMENDO) { estado[fil] = COMENDO; printf("O filosofo %d esta comendo\n", fil) ; sem_post(&s[fil]) ; } } void pegar_garfos(int fil){ int i ; sem_wait(&mutex) ; estado[fil] = COM_FOME ; teste(fil) ;

321

421

.etneilc omixrp o emahc e ohlabart ues enimret oriebrab o euq ta radrauga e )revuoh es( servil sariedac sad amu me es-ratnes eved el odapuco revitse oriebrab o otnauqne etneilc mu agehc eS .olebac o ratroc a ecemoc e etneilc omixrp olep odadroca ajes euq ta emrod oriebrab o ,setneilc matsixe on osaC .etneilc mu ed olebac o odnatroc odapuco revitse oriebrab o es ,merarepse setneilc so arap sariedac ed odatimil oremn mu etsixe e oriebrab mu sanepa ahlabart airaebrab amu mE .sossecorp ertne oacinumoc ed ocisslc amelborp ortuo mu etse ,artskjiD .E .W rop otsoporp mbmaT ocohnimrod oriebrab od amelborP

int i ; for(i=0; i<5; i++) { sem_init (&s[i], 0, 0); estado[i] = PENSANDO ; } sem_init ( &mutex, 0, 1); for (i=0; i<=N;i++){ pthread_create(&tid[i], NULL, filosofos, (void *)i); } for (i=0; i<N;i++) { pthread_join(tid[i],NULL); } } int main(){ } void * filosofos (void * fil){ } void depositar_garfos(int fil){ } for (;;) { pensar((int)fil) ; pegar_garfos((int)fil) ; comer((int)fil) ; depositar_garfos((int)fil) ; } int i ; int i ; sem_post(&mutex) ; sem_wait(&s[fil]) ; sem_wait(&mutex) ; estado[fil] = PENSANDO ; teste((fil+N-1)%N) ; teste(fil+1%N) ; sem_post(&mutex) ;

521

me etsisnoc amelborp O .arobme iav etneilc o servil sariedac revuoh on eS .setneilc sod e soriebrab od oa a razinorcnis

#include <pthread.h> #include <semaphore.h> pthread_t tid1,tid2; sem_t cliente, barbeiro, mutex ; #define cadeiras 10 int esperando = 0 ; void * clientes(void * cli){ sem_wait(&mutex) ; if (esperando <= cadeiras){ esperando = esperando + 1 ; sem_post(&cliente) ; sem_post(&mutex) ; sem_wait(&barbeiro) ; printf("Cliente %d cortando o cabelo\n", cli) ; sleep (4) ; //corta o cabelo } else sem_post(&mutex) ; } void * barbeiros(){ int j ; for(j=0; j<10; j++) { sem_wait(&cliente); sem_wait(&mutex) ; esperando = esperando - 1 ; sem_post(&barbeiro) ; sem_post(&mutex); printf("Barbeiro cortando o cabelo de um cliente\n") ; sleep (4) ; } } int main(){ int i ; sem_init(&mutex, 0, 1) ; sem_init(&cliente, 0, 0) ; sem_init(&barbeiro, 0, 0) ; for (i=0; i<10;i++) pthread_create(&tid1, NULL, clientes, (void *)i); pthread_create(&tid1, NULL, barbeiros, NULL) ; for (i=0; i<11;i++) { pthread_join(tid1,NULL); } }

serotircse e serotiel sod amelborP

621

.rias oa ,rotiel omitl olep e acitrc oes an rartne oa rotiel oriemirp olep etnemos odasu xetum orofmes O .serotircse e serotiel rop sodahlitrapmoc sodad soa osseca on autm osulcxe arap odasu xetum rofmes O .acitrc oiger a rasseca odnereuq serotiel ed oremn o atnoc euq ,rotieltnuoc levirav a avisulcxe etnemautum amrof ed razilauta arap serotiel solep odasu r orofmes o ,oulos atsen :serotiel so arap edadiroirp oulos ariemirP

.odnarepse rotircse mu revuoh es sodad ed esab a rasseca reved on rotiel mu ,sarvalap sartuo mE .levssop ertnemadipar siam o ol -zaf reved ,oarepo amu ratucexe rajesed rotircse mu es ,mroP .osseca o rahlitrapmoc medop serotiel so e avisulcxe amrof ed sodad ed esab a rasseca meved serotircse so ,oulos ariemirp an euq amrof amsem aD .serotircse so aziroirp oulos adnuges A .ol-zaf oredop merajesed o euq serotiel sortuo ,sodad so odnasseca rotiel mu revuoh es sam ,avisulcxe etnemautum amrof ed sodad ed esab a rasseca meved serotircse sO .serotiel so aziroirp ariemirp A .riuges a sadatneserpa ores ,sdaerhtP moc sadatnemelpmi e siotruoC rop sadivlovnesed ,seulos sauD .sodad ed esab a rasseca redop rotircse uo rotiel ortuo muhnen ,oaretla amu odnatucexe revitse rotircse mu eS .etnemaenatlumis serotiel soirv rop otief res edop osseca O .sodad ed esab amu a serotircse e serotiel sossecorp ed etnerrocnoc osseca o raledom arap odazilitu ,1791 me sortuo e siotruoC rop otsoporp ,amelborp etsE

void * leitor(void * i){

int countleitor=0;

pthread_t tid1[N], tid2[N] ; sem_t r, mutex ;

#define N 10

#include <pthread.h> #include <semaphore.h>

sem_wait(&r) ; countleitor = countleitor + 1 ; if (countleitor == 1) sem_wait(&mutex) ; sem_post(&r) ;

sem_wait(&r) ; countleitor = countleitor - 1; //acessa os dados sleep (2) ; printf("Sou o leitor %d\n", i) ;

if (countleitor == 0) sem_post(&r) ; } void * escritor(void * i){ sem_wait(&mutex);

sem_post(&mutex) ;

//atualiza os dados sleep (2) ; printf("Sou o escritor %d\n", i) ; sem_post(&mutex); } int main(){

int i ; sem_init(&mutex, 0, 1) ; sem_init(&r, 0, 1) ; for (i=0; i<N;i++) { pthread_create(&tid2[i], NULL, escritor, (void *)i) ; pthread_create(&tid1[i], NULL, leitor, (void *)i); } for (i=0; i<N;i++) { pthread_join(tid1[i],NULL); } for (i=0; i<N;i++) { pthread_join(tid2[i],NULL); } }

#include <pthread.h> #include <semaphore.h> pthread_t tid1[10], tid2[10]; sem_t r, w, mutex1, mutex2, mutex3 ; #define N 10 int nleitores = 0, nescritores = 0; void * leitor(void * i){ sem_wait(&mutex3) ;

721

oriemirp O

soa ovisulcxe osseca etnarag 3xetum .w e 1xetum ralupinam oredop

os w e r sorofmes sO .serotircse so aziroirp

on

euq serotiel so raeuqolb ri r orofmes olep rassap euq rotircse

)r&(tsop_mes ta )r&(tiaw_mes ed ogidc ed ocolb oa serotiel

,serotircse e serotiel sod amelborp o arap oulos adnuges A .sodahlitrapmoc sodad soa osseca o regetorp arap sodasu ,riuges a adatneserpa

sem_wait(&r) ; sem_wait(&mutex1) ; nleitores = nleitores + 1 ; if (nleitores == 1) sem_wait(&w) ; sem_post(&mutex1) ; sem_post(&r) ; sem_post(&mutex3) ; //acessa os dados sleep (1) ; printf("Sou o leitor %d\n", i) ; sem_wait(&mutex1) ; nleitores = nleitores - 1 ; if (nleitores == 0) sem_post(&w) ; sem_post(&mutex1) ; } void * escritor(void * i){ sem_wait(&mutex2) ; nescritores = nescritores + 1 ; if (nescritores == 1) sem_wait(&r) ; sem_post(&mutex2) ; sem_wait(&w) ; //modifica os dados sleep (1) ; printf("Sou o escritor %d\n", i) ; sem_post(&w) ; sem_wait(&mutex2) ; nescritores = nescritores - 1 ; if (nescritores == 0) sem_post(&r) ; sem_post(&mutex2) ;

} int main(){

int i ; sem_init(&mutex1, 0, 1) ; sem_init(&mutex2, 0, 1) ; sem_init(&mutex3, 0, 1) ; sem_init(&w, 0, 1) ; sem_init(&r, 0, 1) ; for (i=0; i<N;i++) { pthread_create(&tid1[i], NULL, leitor, (void *)i); pthread_create(&tid2[i], NULL, escritor, (void *)i) ; } for (i=0; i<N;i++) { pthread_join(tid1[i],NULL); } for (i=0; i<N;i++) { pthread_join(tid2[i],NULL); } }

821

921

.paws ourtsni amu ed oucexe a atneserper riuges a ogidc -oduesp O .oriedadrev rolav o odubirta labolg levirav e ossecorp oa lacol levirav an oslaf anroter ,oslaf rolav o iussop labolg levirav a eS .oriedadrev rolav o ,acort a n ,odubirta labolg levirav e oriedadrev rolav o lacol

levirav an anroter ,oriedadrev labolg levirav ad rolav o es ,missA .labolg levirav a moc odacort res odetnoc ojuc ,oriedadrev rolav o moc adazilaicini ,lacol levirav amu enifed ossecorp adaC .oslaf rolav o moc adazilaicini

labolg levirav amU .sievirav saud ed odetnoc o acort paws ourtsni A

; )r( nruter

; 1 = kcol

; kcol = r

{)( sat tni

labolg // ;0 = kcol tni

.SAT ourtsni ad oucexe a atneserper riuges a ogidc-oduesp O .oriedadrev rolav o odubirta e oslaf anroter ,oslaf rolav

o eS .oriedadrev rolav o odubirta e oriedadrev anroter ,oriedadrev rolav o es ,amrof atseD .levirav oriedadrev iubirta e ,eslaf rolav o moc adazilaicini ,labolg levirav amu ed rolav o anroter ,SAT ourtsni amu ed oucexe A

levpmorretni

on

amrof

ed

sievirav

saud

ed

odetnoc

a c or T

:pawS

levpmorretni on amrof ed levirav amu ed odetnoc o acifidom e atseT teS dnA tseT :SAT

.pawS e teS dna tseT os seurtsni satsed sauD .autm osulcxe ad amelborp o arap seulos ed oatnemelpmi a metimrep euq siaicepse seurtsni metsixe serodassecorp snugla mE

acitrc oes ad amelborp o arap erawdraH ed seuloS

031

acitrc oes ad mapicitrap euq sossecorp sod aruturtse A

ter

/* CS a arebil - kcol levirav a 0 iubirta */

0# ,kcol evom

{)( noiger_evael

ter

/* pool ,adapuco tse CS a 0 rof on es */

L enj

/* 0 moc arapmoc */ /* acimta oarepo 1 rolav o odubirta

0# ,retsiger pmc

kcol a e retsiger a odubirta kcol ed rolav o */

kcol# ,retsiger sat :L

{)( noiger_retne

labolg levirav */ ;0 = kcol tni

:etniuges a SAT moc oatnemelpmi A .megatnom ed megaugnil-oduesp ores amu A moc sodamargorp e ,sotnemidecorp setse

sodatneserpa siod moc

riuges

.noiger_tixe osu o

noiger_retne ed amrof

,sotnemidecorp levssop amU

seurtsni

sassed

recerefo

; r = yek

; yek = kcol

; kcol = r

; r tni

{)yek ,kcol( paws

eslaf moc adazilaicini labolg % ;0 = kcol tni

131

o ,)adapuco acitrc oes( oriedadrev kcol ed rolav o eS .etnemacimota sodacort os yek e k c ol sievirav sad rolav o ,otnemidecorp etseN

e tr

/* pool

,adapuco tse CS a 1 rof es */

L enj

/* 0 moc yek ed odetnoc o arapmoc */

0 ,yek# pmc

/* etnemacimota - yek e kcol ed odetnoc o acort */ yek# ,kcol# paws :L

{ )yek tni(noiger_retne

ervil tse CS a euq odnacidni eslaf moc adazilaicini labolg % ;0 = kcol tni

os sotnemidecorp so PAWS o u r t s ni a mo C .kcol levirav a o s l af rolav o iubirta euq ,)(noiger_evael

otnemidecorp o odnamahc arebil a ossecorp o acitirc oes a ranimret oA .acitrc oes a atucexe e )(noiger_retne otnemidecorp o animret ossecorp o ,oslaf res rolav od osac oN .otnemidecorp od ortned ,pool me racif ossecorp o e oriedadrev kcol levirav ad rolav o ,adapuco revitse acitrc oes a eS .)(noiger_retne otnemidecorp o amahc ossecorp o acitrc oes an rartne araP

acitrc on oes

; )(noiger_evael

acitrc oes

; )(noiger_retne

{ ) ;;(rof

{ )(ip

231

.kcol levirav oslaf rolav o odniubirta ,acitrc oes a arebil )(noiger_tixe otnemidecorp O .oucexe a aunitnoc ossecorp o e ervil tse acitrc oes a ,oslaf anrot es kcol odnauQ .pool me racif ossecorp o e adapuco tse CS a ,oriedadrev r o f k c ol e d

rolav o eS .)yek(noiger_retne otnemidecorp o atucexe acitrc oes an rartne arap ossecorp adaC ,SAT ourtsni a moc oulos a agolna arienam ed

acitrc on oes

; )(noiger_evael

acitrc oes

; )yek(noiger_retne

; 1 = yek tni

{ );;(rof

{ )(ip

acitrc oes a mazilitu euq ossecorp sod aruturtse A .acitrc oes a osseca rahnag )(noiger_retne otnemidecorp o ratucexe e rodassecorp o rahnag euq ossecorp oriemirp O .kcol levirav 0 rolav o odniubirta ,acitrc oes a arebil

e tr

/* CS a arebil */ 0 ,kcol# evom

{ )(noiger_evael

:)(noiger_evael otnemidecorp O .)ervil acitrc oes( oslaf e n r ot es euq ta pool me a c if ossecorp

331

NIGEB ;meti : i RAV ;recudorp SSECORP )* selbairav derahs eht *( ;tnuoc ,tuo ,ni ,fub : bb ECRUOSER ;0 =: ]N..1[ : tnuoc ,tuo ,ni ;meti FO ]N..1[ YARRA : fub RAV ;01 = N TSNOC
.omsinacem etsed osu o artsuli riuges a odatneserpa amargorp O .ariedadrev a enrot arebil

es anaeloob osserpxe a euq ta osnepsus e autm osulcxe

ossecorp o ones adatucexe S sodnamoc ed atsil a ,ariedadrev b eS

.acitrc oiger an artne ossecorp o odnauq adailava anaeloob osserpxe :b

;S od b nehw V noiger
:etniuges a odnamoc od amrof A .lanoicidnoc acitrc oiger amu ed ortned seurtsni sa ratucexe zev rop ossecorp mu a oditimrep etnemos euqrop aditnarag aut m osulcxe A .sodahlitrapmoc sodad soa osseca

on autm osulcxe etnarag euq omsinacem mu lanoicidnoc acitrc oigeR

)3791 e 2791 nesnaH hcnirB ;2791 eraoH( sianoicidnoC sacitrC seigeR

.cte -

.V e P searepo racoloc mes acitrc oes a razilitu es-edop -

;asrev-eciv e V racoloc ,P oarepo amu ed ragul on ,es-edop -

;V oarepo amu ritimo es-edop -

;P oarepo amu ritimo es-edop -

:olpmexe roP .oazilitu aus me sorre racovorp licf otium ,sorofmes ed osu o es-odnaredisnoC .oamargorp ed megaugnil

amu me sodaroprocni meres ed larutan siam odnes ,autm osulcxe ad amelborp o arap levn otla siam ed seulos matneserper somsinacem setsE

sacitrC seigeR e sianoicidnoC sacitrC seigeR

431

,acitrc oes ad ortned atief .acitrc a oiger an rartne

res eved oidnoc ad oailava a ,sezev satiuM od a setna atief oidnoc ad oailava

ossecorp osserpxe

,ossid

mlA

.acigl

etnemaunitnoc

railavaer

matissecen

sossecorp so euq lanoicidnoc acitrc oiger ad etneinevnocni mU

.ariedadrev enrot es oidnoc a euq ta noiger odnamoc on odaeuqolb acif rodimusnoc ossecorp a r i t er , on otsi o ,)0 = tnuoc( oizav O tse .reffub ajes reffub on o eS .reffub od sotnemele matsixe odnamoc amu

rodimusnoc ,)n <

ossecorp

sievnopsid a euq ta

seisop ,noiger

tnuoc( racif

ariedadrev omsem o

oidnoc

,odaeuqolb

oirrtnoc

osa C

.levnopsid

oisop

etsixe es reffub on sotnemele zudorp rotudorp ossecorp O .autm ed omsinacem omoc lanoicidnoc acitrc oiger mazilitu euq

osulcxe

,rodimusnoc

ortuo e rotudorp mu ,sossecorp siod rop mtnoc amica ogidc ed ohcert O

;remusnoc DNE ;DNE ;)i(remusnoc ;DNE ;1 - tnuoc =: tnuoc ;N DOM )1 + tuo( =: tuo ;]tuo[fub =: i OD 0 > tnuoc NEHW bb NOIGER POOL NIGEB ;meti : i RAV ;remusnoc SSECORP ;recudorp DNE ;DNE ;DNE ;1 + tnuoc =: tnuoc ;N dom ) 1 + ni( =: ni ;i =: ]ni[fub OD N < tnuoc NEHW bb NOIGER ;)i(ecudorp POOL

531

)e(esuac

avitimirp A .sotneve ed alif amu me odaeuqolb acif ossecorp o ,nesnaH hcnirB odnugeS .oidnoc amu ed arepse a ossecorp o aieuqolb e acitrc oiger a arebil ]2791 nesnaH hcnirB[

)e( tiawa

oarepo A .rimusnoc ri omsem o euq sodad so azudorp rotudorp ossecorp mu euq

rarepse atissecen rodimusnoc ossecorp mu ,olpmexe roP .seidnoc satrec rop rarepse ,seautis saremni me ,matissecen setnarepooc sossecorP

.sodahlitrapmoc omoc sodinifed sodad soa osseca on autm osulcxe etnarag noiger odnamoc o euq acifingis o s sI .acitrc oiger ad adartne

an sodaeuqolb macif siamed sO .S odnamoc o ratucexe ri e assap oriemirp o ,noiger odnamoc o etnemaenatlumis masseca setnerrocnoc sossecorP eS

.noiger odnamoc mu ed ortned adasseca res edop etnemos v adahlitrapmoc levirav A .v acitrc oiger a S odnamoc od oucexe a aicossa oaton atse

; S od v noiger

noiger lacitirc odamahc odaruturtse odnamoc mu ed ortned

adahlitrapmoc levirav a rasseca medop etnemos setnerrocnoc sossecorP

; T derahs :v raV

omoc adinifed T opit od ,v ,adahlitrapmoc levirav amu ,omsinacem etse moC

) 27 nesnaH hcnirB ( sacitrC seigeR

.otief res ed levssop

,)esuac e tiawa searepo

siam acitrc oiger( riuges a adatneserpa ,nesnaH hcnirB ed oulos an euq o

631

,ordap sotubirta so moC .dekcolnu e odazilaicini xetum od odatse o ,oazilaicini a spA .sodazilitu os ordap sotubirta so ,LLUN eS .rtta rop sodacificepse sotubirta so moc pm xetum levirav a rtta

azilaicini

;)rtta* t_rttaxetum_daerhtp tsnoc ,pm* t_xetum_daerhtp(tini_xetum_daerhtp tni

avitimirp A .sossecorp solep adahlitrapmoc airmem amu me sadacola res meved xetum sievirav sa ,setnerefid sossecorp ed sdaerht rop xetum ed oazilitu a levssop res araP .setnerefid sossecorp me uo ossecorp omsem on sdaerht razinorcnis arap sodasu res medop xetuM .kcolnu_xetum_daerhtp aiv erebil a a c it r c oiger a mted euq daerht a euq ta ,sadaeuqolb

meuqif acitrc oes a ririuqda odnatnet otse euq sdaerht sartuo euq moc zaf acitrc oes a oditbo ahnet euq kcol_xetum_daerhtp adamahc amu e siabolg res meved xetum sievirav sA .sodahlitrapmoc sodad a osseca on autm osulcxe sodnamoc omoc lat es-retbo so arap )(kcolnu_xetum_daerhtp levssop on e )(kcol_xetum_daerhtp hcnirB rop a odinifed arobmE

razilitu oiger

,nesnaH sdaerhrtP

,acitrc

etnemelpmi

acetoilbib

.oucexe a raemocer redop euq ,rodimusnoc ossecorp o arap ariedadrev anrot es B osserpxe a euq azilanis euq ,)e(esuac oarepo alep odadroca reS .aslaf B osserpxe a es ,)e(tiawa odnamoc od

oucexe alep ,odaeuqolb acif rodimusnoc ossecorp o ,amica amargorp oN

; )( dne ; )e( esuac ; 2S nigeb od v noiger

; dne ; 1S ; )e( tiawa od B ton elihw nigeb od v noiger

rotudorp//

rodimusnoc //

.savitimirp satsed osu o artsuli riuges a odatneserpa ogidc-oduesp O .e sotneve ed alif an sodaeuqolb sossecorp so sodot adroca

731

sdaerhtp moc adamargorp acitrC oigeR ed olpmexE//

,rht ogidc o matucexe euq ,sdaerht 5 sadairc os amargorp etsed lapicnirp odanroter o

onuf aN .levnopsid ocolb mu aitsixe on ,3201 a roirepus rof oremn o eS .ocolb ed oremn mu anroter euq ,eriuqca

amahc ,ocolb mu racola ajesed euq ossecorp O .ocsid ed socolb ed oacola ed aicnereg a zaf ,sodnamoc setsed osu o artsuli euq ,riuges a amargorp O

.odinifedni amargorp od otnematropmoc o e odanroter orre mu ,xetum od airteirporp a on adamahc a atucexe euq daerht a eS .xetum o retbo ri euq daerht a rehlocse arap odamahc rodanolacse o ,sadaeuqolb sdaerht metsixe eS .ol-rebil arap pm xetum od airteirporp daerht alep adamahc

mu ranoisaco ,adamahc atse atucexe xetum od airteirporp daerht a eS .odarebil ajes xetum o euq ta odaeuqolb acif adamahc atse autefe euq

ossecorp o ,odahcef tse j xetum o eS .pm rop odaicnerefer xetum o ahcef

A .xetum levirav a moc rarepo medop ossecorp omsem on sdaerht etnemos

int acquire () { int i ; pthread_mutex_lock(&barrier_lock);\ i = 0 ; while(i < 1024 && disk[i] == 1) i++ ; if (i < 1024) disk[i] = 1 ; pthread_mutex_unlock(&barrier_lock);
.xetum opit od ,kcol_reirrab levirav a adazilaicini

;)pm* t_xetum_daerhtp(kcolnu_xetum_daerhtp tni

;)pm* t_xetum_daerhtp(kcol_xetum_daerhtp tni

#include <pthread.h> pthread_t tid; pthread_mutex_t barrier_lock; int disk [1024] ;


otnemidecorp avitimirp A .kcoldaed avitimirp

831

;)xetum&(kcolnu_xetum_daerhtp e )xetum&(kcol_xetum_daerhtp odnamoc od ortned sadasu os

:sedadeirporp setniuges sa matneserpa

langis_dnoc_daerhtp

tiaw_dnoc_daerhtp

. a ortemrap omoc iussop

dnoc oidnoc levirav

)dnoc* t_dnoc_daerhtp(langis_dnoc_daerhtp tni


avitimirp A

.xetum o e dnoc oidnoc levirav a os sortemrap sO ;)xetum* t_xetum_daerhtp ,dnoc* t_dnoc_daerhtp(tiaw_dnoc_daerhtp tni

:euges omoc sadinifed ,)(langis_dnoc_daerhtp e )(tiaw_dnoc_daerhtp searepo sa iussop sdaerhtP acetoilbib A

} int main(){ int i; for(i=0;i<1024;i++) disk[i] = 0 ; pthread_mutex_init(&barrier_lock,NULL); for (i=0;i<5;i++) pthread_create(&tid, NULL, thr, NULL); } k); void thr(int i){ int j, k ; } printf(" EU SOU A THREAD : %d\n",i); for (j=0; j<10; j++){ k = acquire () ; if(k < 1024) printf("THREAD: %d OBTIVE O BLOCO %d \n",i, return(i) ; sleep(1); } for (i=0;i<N;i++) pthread_join(tid, NULL); printf("FIM DO MAIN\n");

#include <pthread.h> pthread_cond_t cond0 ; pthread_cond_t cond1 ; pthread_t tid0; pthread_t tid1; pthread_mutex_t mutex; int buffer ; void * produtor(){ int j, k ; for (j=0; j<100; j++){ pthread_mutex_lock(&mutex) ; while (x == 1) pthread_cond_wait(&cond1, &mutex) ; buffer = j * 5 ; X = 1 ; pthread_cond_signal(&cond0) ; pthread_mutex_unlock(&mutex) ; } } void * consumidor(){ int j, k ; for (j=0; j<100; j++){ pthread_mutex_lock(&mutex) ; while (x == 0) pthread_cond_wait(&cond0, &mutex) ; printf (Valor do buffer: %d\n, buffer) ; X = 0 ; pthread_cond_signal(&cond1) ; pthread_mutex_unlock(&mutex) ; } }

int main(){ pthread_mutex_init(&mutex,NULL); pthread_create(&tid0, NULL, produtor, NULL);

ossecorp

ossecorp

revuoh

sodnamoc

xetum

931

acitrc oiger a arebil e

on

mu

son es

aieuqolb

otiefe

adroca

sadasu

.dnoc oidnoc levirav an sodaeuqolb sossecorp

)dnoc&

zudorp

.savitimirp satsed osu o artsuli riuges a amargorp O

)dnoc&(langis_dnoc_daerhtp

,acit rc

;kcolnu_xetum_daerhtp/kcol_xetum_daerhtp

dnoc

,xetum&(tiaw_dnoc_daerhtp

on

dnoc oidnoc levirav an odaeuqolb

oidnoc levirav an atucexe a euq

oiger

langis_dnoc_daerhtp

amu

sadaicossa oarepo

oarepo

oarepo

os a a a ;

041

.rotinom mu ed osiv rop es a atneserpa mu riuges a arugif A A .)langis oarepo( amu ossecorp arepse

ortuo a

mu

adazilanis ossecorp

oidnoc a

.)tiaw( )

oidnoc (

ed

raeuqolb

metimrep

oidnoc

siaicepse

sieviraV

.adatucexe ajes adamahc aus a euq e odarebil ajes rotinom otnemidecorp adamahc oa a o euq a arepse oriemirp siod a o eS r a c if odnuges o euq

o euq e enimret ,ratucexe omsem atief

otnauqne mu

rezaf

,otnemidecorp .avisulcxe

omse m

opmet ed

mamahc

sossecorp

etnemautum

amrof

sotnemidecorp setsed oucexe a ,mroP .rotinom o masseca euq sossecorp so sodot a snumoc os rotinom mu ed sotnemidecorp sO .otejbo od laicini odatse o alanissa euq oazilaicini ed ogidc mu e ,otejbo etse malupinam euq euq sotnemidecorp sodad so so ,otejbo euq odanimreted ed mu ed odatse mu o matneserper rotino m mU

mtnoc

sodad

otartsba

o p it

]47 eraoH ,37 nesnaH hcnirB [ rotinoM

.rodimusnoc ossecorp olep artuo e rotudorp ossecorp olep amu ,oidnoc sievirav saud sadazilitu os euq evresbO .)1dnoc&(langis_dnoc_daerhtp oarepo alep erroco euq o ,rodimusnoc ossecorp olep odazilanis res ta )1dnoc&(tiaw_dnoc_daerhtp oarepo an odaeuqolb acif rotudorp

ossecorp o ,agolna arienam eD .)dnoc&(langis_dnoc_daerhtp oarepo ad oucexe alep ,x levirav 1 rolav o e reffub levirav rolav mu odubirta ret omsem o spa erroco euq o ,rotudorp ossecorp olep odazilanis ajes euq ta ,)0dnoc&(tiaw_dnoc_daerhtp oarepo an ,odaeuqolb acif rodimusnoc

ossecorp o ,orez a laugi rof x levirav ad rolav o es ,amica amargorp oN

} pthread_create(&tid1, NULL, consumidor, NULL); pthread_join(tid0, NULL); pthread_join(tid1, NULL);

141

1P e 0P ,odadroca 1P eS .ratucexe medop 1P e 0P ,odaeuqolb 1P ossecorp mu etsixe e 0P ossecorp mu rop adatucexe langis.x oarepo a eS

:etniuges o rigrus edop euq amelborp mu ,searepo satse odnaredisnoC .sotiefe zudorp on oarepo a ,sodaeuqolb sossecorp metsixe on S .x oidnoc levirav an odaeuqolb ossecorp mu adroca

; )( langis.x

oarepo A .x oidnoc levirav an atucexe a euq ossecorp o aieuqolb

; )( tiaw.x

oarepo A

; noitidnoc : y ,x rav

oaton a moc oidnoc opit od ,y e x sievirav sa rinifed es-edop ,olpmexe roP arap .sosrucer sadazilitu ed arepse os e a otse euq sossecorp ed raeuqolbsed/raeuqolb oa sadaicossa

,rotinom

otiecnoc

os oidnoc sieviraV .rotinom od )2corP uo 1corP ,0corP( otnemidecorp mu ratucexe arap rotinom od oarebil ad arepse a sodaeuqolb otse euq ,2P e 1P ,0P sossecorp solep adamrof ,alif amu mbmat mtnoC .siabolg sodad so e ,rador a aemoc rotinom o odnauq odatucexe euq ,oazilaicini ed ogidc o ,sotnemidecorp srt rop odamrof rotinom mu atneserpa amica arugif A

rotinoM mu ed acitmeuqsE osiV

oazilaicinI ed ogidC

3corP
2P 1P 0P

2corP

1corP

siabolG sodaD

241

o N euq

.ritsixe ,

es

,x

oidnoc

levirav

an

odaeuqolb

ossecorp

mu

adroca

)x( eunitnoc

oarepo a atucexe e ervil osrucer o euq alanissa euq

,esaeler

otnemidecorp o amahc mted o euq ossecorp o osrucer od oarebil es ,) x O . ( yaled oarepo e o alep ,odaeuqolb

araP .odapuco tse osrucer o tseuqer iussop amahc e euq

ossecorp mu a

esaeler
osseca

tseuqer
ralortnoc

:sotnemidecorp arap odasu

siod

osrucer

ovisulcxe

rotinom O .sossecorp siod rop e rotinom mu rop odamrof riuges a amargorp O .

rotinom ,ssalc ,ssecorp

sevahc sarvalap salep sodacifitnedi ,serotinom e

sessalc ,sossecorp :sodad ed sotartsba sopit srt uotnecserca nesnaH hcnirB lauq an ,lacsaP megaugnil ad osnetxe amu etnerrocnoC lacsaP

.rotinom ed osu o acifilpmexe euq etnerrocnoC lacsaP amargorp mu odatneserpa res riuges A .) erudecorp ad ourtsni amitl a langis o ( rotinom o arebil e langis atucexe 0P ,missA .rotinom

od otnemidecorp mu ed ortned odnamoc omitl o res erpmes eved langis oarepo a ,selpmis amrof amu ed amelborp o evloser ]7791 nesnaH hcnirB[ etnerrocnoC lacsaP megaugnil an ,nesnaH hcnirB rop adatoda oulos A

.rotinom

rotinom o arebil on e 1P ed oidnoc a azilanis 0P )b

.oidnoc artuo

rotinom o odnarebil ,aieuqolb es e 1P adroca 0P )a

:oulos ed sedadilibissoP

osulcxe ad oipicnirp o aloiv euq o ,rotinom on etnemaenatlumis sovita macif

;rotinom o rarebil 1P odnauq oucexe a aemocer 0P

ed arepse a raeuqolb es 1P odnauq oucexe a aemocer

0P

.autm

;rotinom o erebil 0P euq arepse 1P

o arebil euq o ,oidnoc ed arepse a eieuqolb es 0P euq arepse 1P

341

.oucexe me acoloc so euq ,

rotinom o mebecer sossecorp sO .etnemroiretna sodinifed

opit od sievirav sa sadaralced os ,).dne/nigeb ohcert( amargorp od niam oN

.)odaicnatsni( odaralced rotinom o odnauq odatucexe euq )rotinom od dne/nigeb( ,oazilaicini ed ogidc mu iussop rotinom

O .)

yrtne

adavreser arvalap a mes( rotinom oa siacol sotnemidecorp metsixe

on ,olpmexe oN .

yrtne

adavreser arvalap a mtnoc euq so os sossecorp .odaziromem on , otsi

solep sievsiv os euq sotnemidecorp sO

eunitnoc

oarepo alep odareg lanis o ,odadroca res a ossecorp odnitsixe

Type user = process ( r = resource );

etnerrocnoC lacsaP amargorP//

tini oarepo an ,ortemrap omoc ,rotinom


e

ssecorp

,odidrep

end.

procedure entry release ;

type resource = monitor

begin

procedure entry request ;

begin

var

free : = true;

end

begin

begin

x :

free : boolean ;

r.request ; end continue ( x ) ; free : = true ; if not free them queue ; delay ( x ) ; free : = false ;

r.release ; end; Type user1 = process ( r = resource ); begin r.request ; r.release ; end; begin var p0 : user ; p1 : user1 ; m : resource ; init po ( m ) ; init p1 ( m ) ; end;

441

moc oirnib orofmes mu ed oatnemelpmi a atneserpa riuges a ogidc O .rotinom

.dne .amargorp o ritucsiDA


type semaphore = monitor ; var busy = boolean ; nom_busy : queue ; procedure entry P begin if busy then delay (nom_busy) ; busy = free ; end; Procedure entry V begin busy = false ; continue (nom_busy); end ; begin busy = false ;

541

;1 + tnuoc =: tnuoc ;XAM dom )1 + ni( =: ni ;i =: ]ni[reffub )* reffub on otnemele ovon mu acoloc *( oiehc tse reffub o ,rimusnoc arepse// ; )c( yaled )XAM = tnuoc( fi { )regetni :i( atisoped yrtne erudecorp ; eueuq : c ,p ;regetni : tuo ,ni ,tnuoc ;regetni fo ]XAM..0[ YARRA : reffub rav ; 01 = XAM tsnoc ; rotinom = reffub_dednuob epyt
.odatimil reffub od amelborp o arap oulos amu atnemelpmi riuges a odatneserpa rotinom O

odatimil reffub od amelborP

.rotinom moc oirnib on orofmes mu ed oatnemelpmi a adatneserpa res riuges A

begin

Procedure entry V ()

procedure entry P ()

type semaphore = monitor ;

end.

end; var nproc = n;d. end ; begin end; begin continue (non_busy) ; nproc++; if nproc<0 then delay (non_busy) ; nproc--; nproc = int ; non_busy : queue ;

641

.oazinorcnis arap sorofmes ezilitu e

sdaerht omoc setnajaiv so eledoM .amelborp


.oirrtnoc oditnes me rassevarta edop

etse arap oulos amu avlovneseD

oiR ednarG od oiger ad etnajaiv mu euq etnop a odassevarta meret atlA atserolF ad setnajaiv ocnic spa etnemoS .oiR ednarG od oiger ad setnajaiv soa oaler me edadiroirp meussop atlA atserolF ad oiger

ad setnajaiV .zev adac ed aossep amu etnemos rassap arap edadicapac moc ,oriedalifsed mu me etnop amu ed aicntsixe a eredisnoC .oazinorcnis arap sorofmes ezilitu e sdaerht omoc sorrac so eledoM .amelborp etse arap oulos amu avlovneseD .soditnes sod mu adac me ,aur adac ed levmotua mu ,etnemadanretla ,rassap eved euq e saur saud san soditnes siod son otisnrt o euq ,artuo oaler me aur amu ed edadiroirp etsixe on euq ,otnemazurc mu me sievmotua ed megassap a ralortnoc arap orofmes mu ed aicntsixe a eredisnoC .1 .2

rotinom// .dne rotinom od // nigeb } ;)c(eunitnoc )* rotudorp o azilanis *( ;1 + tnuoc =: tnuoc ;XAM dom )1 + tuo( = tuo ; ]tuo[reffub = I )* reffub on otnemele ovon mu acoloc *( oizav tse reffub o ,rizudorp arepse // ; )p( yaled )0 = tnuoc( fi { )regetni :i rav( ariter yrtne erudecorp } ;)p(eunitnoc )* rodimusnoc o azilanis *(

Exerccios

741

atnoc euq ortuo olep rarepse eved otne e ,005 ta atnoc sossecorp sod mU .sorofmes ed osu o moc sea saus mazinorcnis euq )SDAERHT( sossecorp siod rop odamrof etnerrocnoc amargorp mu avercsE .sreffub soa osseca on autm osulcxe a arap sorofmes ezilitU .reffub od seamrofni sa odariter revah arodimusnoc daerht ad sioped rizudorp a ratlov medop etnemos sarotudorp sdaerht sa e reffub on seamrofni meritsixe es rimusnoc edop etnemos arodimusnoc daerht A ed edadicapac meussop ed emosnoc oriemirp .8

.otnemele ocin mu ranezamra

1b e 0b sreffub sO .)1b ed emosnoc sioped e 0b

( 1b reffub on 1p daerht ad e 0b refub on 0p daerht 1p e 0p( sarotudorp saud e )c( arodimusnoc


.7 .rodimusnoc od e rotudorp od

ad )orietni rolav mu( eamrofni ebecer arodimusnoc daerht A .onrete pool mu matucexe euq ,)

amu ,sdaerht srt rop odamrof etnerrocnoc amargorp mu avercsE

sea sa razinorcnis arap

nosreteP ed oulos ad osu o moc etnerrocnoc

amargorp mu avercse ,otnemele mu ed reffub mu mahlitrapmoc rodimusnoc mu e rotudorp mu ,sossecorp siod euq odnaredisnoC .odnimirpmi e atsil ad seretcarac so odnariter etnemaunitnoc acif .6

rosserpmi

ossecorp O .etnemacimanid sodacola os sodon sojuc ,adaedacne atsil amu me acoloc so e odalcet od seretcarac l .autm osulcxe ad amelborp o arap sea saus mazinorcnis euq e

rotiel ossecorp O
,

,nosreteP ed oulos ad osu o moc

e ,otinifni pool mu matucexe euq

rosserpmi
.5 ,emirpmi

rotiel ,setnerrocnoc sossecorp siod rop odamrof amargorp mu avercsE


.oiehc revitse omsem o odnauq ,reffub o rimirpmi arap otnemidecorp o amahc rosserpmi ossecorp O .)seisop 231( reffub

on seretcarac riresni arap ,atisoped otnemidecorp o amahc rotiel ossecorp O .emirpmi e atisoped ,sotnemidecorp siod moc ,rotinom mu .ol-imirpmi eved avercs E .4

rosserpmi ossecorp

o oiehc tse reffub o odnauQ

.seisop 231 ed reffub mu me odnacoloc e odalcet od seretcarac odnel acif

rotiel ossecorp O .sorofmes ed osu o moc sea saus mazinorcnis


euq e ,otinifni pool mu matucexe euq ,

rosserpmi e rotiel ,)sdaerht(


.3

setnerrocnoc sossecorp siod rop odamrof amargorp mu avercsE

841

.reffub od otnemele mu

anroter

fuBteg

optnemidecorp O .reffub on

odanezamra res eved euq rolav mu ortemrap omoc ebecer otnemidecorp O .

fuBtup

fuBtup e fuBteg

,serudecorp saud rop otsopmoc e rotinom mu avercsE )11

sotnemele 231 ed reffub mu atnemelpmi euq

.1 rolav o moc sadapuco

0 moc

sadacram os sievnopsid seisop sA .airmem ed sreffub ed oapuco ed apam mu mtnam euq e ,seisop 001 edodahlitrapmoc rotev mu masseca euq

,) ( reffuBarebil e ) ( reffuBacola sotnemidecorp so avercsE


/*

c oidnoc levirav

an odaeuqolb ossecorp mu adroca */ /* levirav an ossecorp /* o

; ) c ( langis t_dnoc_daerhtp

kcol acitrc oiger a adaicossa ,c oidnoc


*/

aieuqolb

; )c ,kcol&( tiaw_dnoc_daerhtp ;)kcol&(kcolnu_xetum_daerhtp


/*acitrc oes

c oidnoc levirav amu enifed */ ; c t_dnoc_daerhtp

/*acitrc oes a arebiL */

a ratucexe ed sdaerht salpitlm eniverP */

;)kcol&(kcol_xetum_daerhtp kcol t_xetum_daerhtp

/* xetum opit od levirav amu omoc kcol enifed */ ;

:sodnamoc so moc sdaerhtP me adatnemelpmi acitrc oigeR .01

; eslaf == )r( esuni esle ; p ravita llun =! p fi ; r ed alif ad oriemirp = p :)r(qed ; eurt = esuni esle } ; )p(kcolb ; r ed alif an p eresni {)r( esuni fi :)r(qne
:euges omoc sodinifed ed sosrucer ed osu o malortnoc euq ,avisulcxe etnemautum amrof

,eueuqed e eueuqne sotnemidecorp


.9 .005 ta atnoc euq

sod oatnemelpmi amu aurtsnoc sorofmes ed osu o moC

DAERHT alep aemoc oucexe a euq eredisnoC .asrev-eciv e ,0001 ta

941

?)s(avitimirp )s(amugla ed osu o moc adarohlem res airedop oulos A .otnemele ocin mu ed reffub mu mahlitrapmoc euq arodimusnoc amu e arotudorp amu ,sdaerht saud rop o d a m r of amargorp

mu avercse ,enimret ahlif daerht amu euq ta atucexe a euq daerht a aieuqolb avitimirp

)( nioj _daerhtp onuf


a moc adairc

a euq e daerht

)cnufemon(etaerc_daerhtp
amu euq odnopuS

/*acitrc oes

:sodnamoc so moc sdaerhtP me adatnemelpmi acitrc oigeR

.oizav reffub e oiehc reffub ed seautis san oazinorcnis ed edadissecen a eredisnoC

/* xetum opit od

kcol levirav amu enifed */ ;kcol t_xetum

a ratucexe ed sdaerht salpitlm eniverP */

;)kcol&(kcol_xetum

/*acitrc oes a arebiL */ ;)kcol&(kcolnu_xetum

Bibliografia
?)si(lauQ )21

051

.megasnem amu ed otnemibecer o ta odaeuqolb acif atucexe a euq ossecorp o ,etnaeuqolb oarepo assE .gsm amu rebecer arap ossecorp mu rop adazilitu :eviecer

.etnaeuqolb on uo etnaeuqolb res edoP .gsm amu raivne arap ossecorp mu rop adazilitu :dnes

eviecer e dnes os sacisb savitimirp

saud sA .airmem mahlitrapmoc on euq sossecorp ertne seamrofni ed acort a etimrep snegasneM ed acorT rop sossecorP ed oacinumoc A

.sossecorp so ertne oacinumoc ed omsinacem ( olep levsnopser ed acort ed O.S o ,oledom etseN .)segassem mahlitrapmoc sievirav

gnissap

snegasnem so

svarta meS

seamrofni

sossecorp

,adahlitrapmoc

airmem

.sadahlitrapmoc

ed osu od svarta seamrofni macort e sievirav mahlitrapmoc ossecorp so ,adahlitrapmoc airmem moC saremni me ,oacilpa amu .seamrofni racort matissecen seautis sossecorP

ed

setnenopmoc

,setnarepooc

.ecafretnI gnissaP egasseM :IPM erbos odutsE .otnemidecorP ed atomeR adamahC .opurG me oacinumoC .oacinumoC ed savitimirP .snegasneM ed acorT .adahlitrapmoC airmeM :sossecorP ertne oacinumoC

5.1 Comunicao entre Processos

Mensagens Processos por Troca de 5. Comunicao entre

151

eviecer oarepo an ,etnetemer o acifitnedi euq

opmac on 1- rop odacidni euq o ,etnetemer reuqlauq ed ebecer rodebecer o e rodebecer o acifitnedi etnetemer o acirtmissa aterid oacinumoc aN

.etnetemer o acifitnedi rodebecer o e rodebecer o acifitnedi etnetemer o , otsi ,etnemautum macifitnedi es sossecorp so acirtmis aterid oacinumoc

aN .ateridni uo aterid res edop snegasnem ed acort rop oacinumoc A

on

ylper

oarepo

.sorre

mes

adibecer

iof

dnes

moc adaivne megasnem ed oamrofni amu

amu euq racidni edop etnemselpmis uo atsopser edoP .adibecer megasnem amu a rednopser

retnoc

arap ossecorp mu rop adasu ,ylper etnetsixe oarepo artuo amU .dnes oarepo amu moc adaivne ,megasnem amu ed otnemibecer o ta odaeuqolb ecenamrep eviecer oarepo amu atucexe euq ossecorp mu ,amrof

atseD .etnaeuqolb ,etnemlamron ,eviecer oarepo a e ,etnaeuqolb on uo etnaeuqolb res edop dnes oarepo A .searepo s aticlpmi ,snegasnem ed acort matnemelpmi euq sametsis son sossecorp ertne oazinorcnis A

main ( ) {

// processo 0

main ( ) {

/ * processo 0 * /

.etnaeuqolb oarepo amu

send (t1, &m); send (t1, &m); :.xE

main ( ) { // processo 1 main ( ) { // processo 1 } } receive (t0, &m); -

251

.savitimirp satsed osu o artsuli riuges a ogidc-oduesp O .snegasnem ed arepse a sodaeuqolb sossecorp ed alif an ,odaeuqolb racif ossecorp o ,p atrop an snegasnem meritsixe on eS .p atrop adaicossa snegasnem ed alif ad megasnem ariemirp a retnoc m ,oarepo ad onimrt oA .megasnem amu rebecer arap ossecorp mu rop adazilitU

.p atrop sadaicossa ,sadimusnoc on sA adnia .p atrop snegasnem amu arap ed m alif amu me amu sadacoloc raivne ores mu snegasnem a etimreP

megasnem

ossecorp

.sadidrep ores sadibecer on p atrop a sadaicossa snegasneM .ritsixe ed axied p atrop a ,oarepo ad onimrt oA .atrop amu animile oarepo atsE

.adairc atrop ad oacifitnedi a mtnoc p ,oarepo ad onimrt oA .oacinumoc ed atrop amu rairc arap adazilitu oarepo atsE

;) ( etaerc-trop = p
:os satrop erbos searepo sA .atrop osseca ed otierid o meussop euq sossecorp so sodot ed uo rodairc ossecorp od res edop atrop amu erbos sadaivne snegasnem rebecer ed otierid O .stekcos ,HCAM lanoicarepo ametsis :.sxE .xobliam uo atrop adanimoned ,macinumoc es sossecorp so lauq ad svarta airidemretni edaditne amu etsixe ,ateridni oacinumoc a odnauQ

p0 ( ) { // processo 0 port_t p;
;)m ,p( eviecer ;)m ,p( dnes ;)p( yortsed-trop

receive (-1, &m); }

351

.adas e adartne ed searepo s sodanoicaler os sonretxe sossecorp e oucexe me samargorp so os sonretni sossecorP .sonretxe e sonretni :sossecorp ed sopit siod iussop ametsis O

.setnerrocnoc sossecorp omoc sadatnemelpmi marof ametsis od sedadilanoicnuf siamed sA .sossecorp ertne oacinumoc ed senuf sa e sossecorp sortuo rop sadamahc res medop euq sossecorp ed otnemaicnereg e oairc ed senuf sa ,otnemanolacse ,sepurretni ed sacisb ed sia m otnematart senuf sa ,otxetnoc moc ed oaruatser mu iussop e otnemavlas O

,oelcn

ametsis

.sossecorp ertne oacinumoc a ratnemelpmi arap snegasnem ed acort uozilitu nesnaH hcnirB ,]0791 nesnaH hcnirB ,metsyS gnimmargorpitluM a fo suelcuN ehT[004CR rodatupmoc o arap odivlovnesed lanoicarepo ametsis oN

p1 ( ) {

// processo 1

create (p1) ; create (p0); while(1){ while(1){ p=port_create();


{ )(niam

} } send (p, &m); receive (p, &m); -

451

,sievssop os oacinumoc ed samrof sairv ,oledom etseN .

sossecorp ed

opurg mu evlovne euq oacinumoc ed oledom mu opurG me oacinumoC

iof megasnem a es ,ametsis od oelcn olep uo ossecorp ortuo mu rop adaivne iof atsopser a es acificepse reffub o e )

tluser .ametsis od

rewsna(

ossecorp od otnemaeredne ed oapse o arap adaipoc

agehc atsopser a odnauQ .odacificepse ta atucexe a euq ossecorp o aieuqolb

.avitimirp ad oucexe a spa etnemataidemi aunitnoc

rewsna dnes

oarepo

atucexe

amu rop odnarepse tse es odavita megasnem ad rednes O .megasnem a uoivne euq ossecorp od alif an acoloc o e adibecer megasnem alep odazilitu reffub on

rewsna

atsopser

aipoc

:)reffub ,rewsna ,tluser( rewsna dnes

ritimsnart arap levnopsid odanrot e alif ad odivomer reffub O .megasnem ed reffub od edaditnedi ad e , etnetemer o ossecorp ossi od

)egassem(
od

emon .alif

essop me

,ecetnoca

odnauQ

aus

euq ta odaeuqolb acif ossecorp o

:)reffub ,egassem ,rednes( egassem tiaw

.megasnem ad reffub od oacifitnedi a rebecer spa aunitnoc etnetemer O .megasnem amu odnarepse revitse es odavita rotpecer O .

od alif an acoloc e sreffub ed loop od ortned levnopsid reffub oriemirp o arap

egassem

megasnem a aipoc

:)reffub ,egassem ,reviecer( egassem dnes


:savitimirp setniuges

sad osu o moc atief res edop ametsis on sonretni sossecorp so ertne oacinumoc A .ossecorp adac arap snegasnem ed alif amu e ametsis od snegasnem ed sreffub ed otnujnoc mu aicnreg ametsis od oelcn O

5.2 Comunicao em Grupo


.etnetsixe on ossecorp mu a adaivne sreffub ed loop o arap odanroter

reffub

on eugehc atsopser amu euq

:)reffub ,rewsna ,tluser( rewsna tiaw

euq

ossecorp

.atsopser

.atsopser amu

megasnem ad odetnoc od , ed tse e odadroca ajes

)rednes(

ossecorp amu

adatisoped

megasnem

reviecer

rotpecer

551

odnetnoc odon adac a adaeredne ajes megasnem amu sanepa euq amrof ed ,mediser somsem so edno odon o atnoc me ravel edop sossecorp ertne oaretni ed opit etsed oatnemelpmi a ,megasnem amu ed osufid ad olpmexe o adnia odnaredisnoC .oacinumoc ad oatnemelpmi a arap sodazilitu res massop setneicife siam solocotorp euq etimrep euq o ,oirusu oa setnerapsnart etnemlatot os oatnemelpmi aus ed sehlated so ,levn otla siam ed omsinacem mu opurg me oacinumoc a omoC .otnop-a-otnop snegasnem ed acort ad oa odarapmoc ,oacinumoc ed opit etse rop odicerefo res edop euq ohnepmesed roiam oa otiepser zid ,opurg me oacinumoc ad megatnav adnuges A .mabecer a sossecorp so sodot euq arap opurg etse )osufid ed( megasnem acin amu raivne rossime o arap atsab ,opurg mu me sodulcni merof onitsed sossecorp so es ,otnatne oN .soirtanitsed sossecorp so merof sotnauq snegasnem satnat raivne reved etnetemer ossecorp o ,missA .rotpecer ossecorp adac arap

megasnem amu raivne euq ret ,rossime ossecorp o ,opurg me oacinumoc ed savitimirp matsixe on euq e sossecorp solpitlm arap adaivne res aved megasnem amu euq es-odnopus adaicnedive res edop megatnav ariemirp A .)rotpecer ossecorp mu e rossime ossecorp mu evlovne euq a( otnop -a-otnop snegasnem ed acort oarapmoc me recerefo edop oacinumoc ed opit etse euq ohnepmesed rohlem o omoc missa ,sossecorp solpitlm odnevlovne oacinumoc ad osserpxe ed edadilicaf roiam a ratic es-edop opurg me oacinumoc ed oledom od snegatnav siapicnirp sa ertnE .setnaeuqolb-on uo setnaeuqolb res medop opurg mu ed sorbmem rop sadizudorp snegasnem ed opecer a e opurg mu arap snegasnem ed osufid a ,

otnop-a-otnop snegasnem ed acort sodot-arap-sodot oacinumoc mu-arap-sodot oacinumoc


sossecorp

an euq amrof amsem aD .opurg od setnenopmoc siamed so arap megasnem amu aivne opurg mu ed orbmem adac ,

aN .oirtanitsed ossecorp ocin mu arap megasnem amu maivne opurg omsem mu a setnecnetrep sossecorp so

aN .opurg od etnatser o arap sodad aivne opurg od sorbmem sod mu ,osufid ed adamahc mbmat ,

sodot-arap-mu oacinumoc aN
.sodot-arap

-sodot e mu-arap-sodot ,sodot-arap-mu oacinumoc a racatsed es-odnedop

651

2P 3P

1P 6P 0P megasnem

4P

.ociuqrreih odahcef mu e ociuqrreih on otreba mu ,sopurg siod matneserpa riuges a sarugif sA .oa a ratucexe reved euq rodahlabart o ehlocse e opurg oa sadaeredne snegasnem sa ebecer meuq rodanedrooc o .serodahlabart so os siamed so e rodanedrooc o ossecorp mu ,osac etseN .

ociuqrreih omoc

odacifissalc opurg o aiuqrreih odnitsixE .siaugi os opurg oa mecnetrep euq sossecorp so sodot , otsi ,sorbmem sues so ertne aiuqrareih etsixe on odnauq r

ap opurg mU .sorbmem sues moc meuqinumoc es opurg

od arof ed sossecorp euq levssop

sotreba sopurg soN .aditimrep opurg sodahcef sopurG .levirav otnatrop


.etnatsnoc opurg ed opit etsed

od sorbmem so ertne oacinumoc a etnemoS .opurg o moc meuqinumoc es arof ed sossecorp euq metimrep on

opurg ed opit etsed ohnamat O .oirssecen euq erpmes opurg od rias e rartne medop sossecorp ,

ocimnid opurg mu mE

sotnemele ed oremn o , otsi ,ohnamat O .sorbmem ed otnujnoc omsem o moc erpmes ecenamrep ,odamrof odis ret spa ,es

ocittse opurg mU
sociuqrreih

uo serap ,sodahcef uo sotreba ,socimnid uo socittse me sodacifissalc


res medop sopurg ,anretni oazinagro aus emrofnoC .oaredisnoc me sodavel res meved ,sopurg sod anretni oazinagro sodanoicaler etnemlaicepse ,sotcepsa soirv ,opurg me oacinumoc aN

.odon on megasnem a rebecer meved euq sossecorp so sodot a adahnimacne res onitsed odon mu me agehc megasnem

a odnauq ,odom etseD .megasnem a rebecer maved euq sossecorp

751

sametsis son e sodubirtsid sametsis son sodasu oacinumoc ed omsinacem etneicife mu os ) C P R( aicntsid a` sotnemidecorp ed sadamahc sA

CPR oledom O

.)CPR( aicntsid a otnemidecorp ed adamahc a :atsopser a odnarepse odaeuqolb acif e oivres mu odnaticilos rodivres mu a megasnem amu aivne etneilc mu ,oledom esseN .)]09aB[soileH .xe( salelarap saniuqm arap sianoicarepo sametsis me e ).cte ,TN swodniW ,]68cA[hcaM ,]98rA[surohC ,]09uM[abeomA( sametsis soirv

me odasu iof oledom essE .setneilc so ,sossecorp sortuo a soivres mecenrof euq serodivres mu so ,setnarepooc ed aidi sossecorp a ed opurg mu me lanoicarepo oledom O

ametsis

raruturtse

ednopserroc

rodivres/etneilc

.opurg od setnapicitrap siamed so sodot a megasnem amu ahnimacne ,0P ,opurg od rodanedrooc o ,ociuqrreih odahcef opurg oN

.opurg od sorbmem so sodot rop adibecer res ,opurg oa etnecnetrep on ,6P ossecorp olep adaivne megasnem a ,ociuqrreih on otreba opurg od osac oN

odahcef ociuqrreih opurG

2P

3P 4P

ociuqrreih on

otreba opurG

5P

5.3 Remote Procedure call


5P 1P

0P

851

. etneilc oa elortnoc o anroter e animret ,sodatluser so ebecer tneilc buts erudecorp a ,etnemlaniF .revres buts ed adamahc

oarepo asse azilaer euq erudecorp A .etneilc ossecorp oa atsopser oarepo an ed a megasnem adazilaer ad oivne e ad e sodatluser oucexe

sod ad

oacoloC mif oN

:asrevni

,erudecorp a amahc

.megasnem

adacificepse

erudecorp

sortemrap

sod oartxe a edecorp ,megasnem a ebecer odnauq ,rodivres O .rodivres rodassecorp/ossecorp oa megasnem asse etimsnart e adamahc erudecorp ad oacifitnedi a odnanoicida ,megasnem amu me acoloc so e sortemrap so ebecer erudecorp assE .tneilc buts adamahc erudecorp amu rop

etneilc od odal on adinifed aicntsid adamahc res edop euq onuf adoT

:etniuges o ]48iB[nosleN rop otsoporp otnemanoicnuf ed ameuqse O .selpmis ot missa on adamahc amu ed otnemanoicnuf o ,CPR mu ed osac oN

.)parT .xe( acisf arutetiuqra ad socifcepse sosrucer ed osu o moc sadacovni os e )aniuqm ad serodartsiger son .xe( sortemrap so serudecorp sass E .soirusu sod samargorp solep sodamahc mebecer os euq

sotnemidecorp rop sadatnemelpmi os ametsis ed sadamahc sa sianoicidart sianoicarepo sametsis mu retbo son sametsis son ed ,olpmexe adamahc osu o ro P amu .sianoicidart a ocitndi sianoicarepo

otnemidecorp CPR

otnematropmoc soN

etimrep

ed

sodubirtsid

sametsis

.odadroca etneilc o e P aniuqm a arap Q aniuqm ad sodaivne os sodatluser sO .aemoc otnemidecorp od oucexe a o( e osnepsus aniuqm etneilc me O .sodauqeda sortemrap mu amahc so odnaivne o( ,P )rodivres aniuqm

,Q

amu

otnemidecorp

)etneilc

amu me amargorp mu ,CPR mu mE .aniuqm artuo me odatucexe odnes amargorp mu rop aniuqm amu me otnemidecorp mu ed adamahc a ritimrep lapicnirp aidi A .sianoicidart od oamargorp osnetxe ed snegaugnil ]48iB[ san etnetsixe O

larudecorp

oledom

adubirtsid

amu

CPR

oledom

.rodivres/etneilc oledom o moc odroca ed sodazinagro ,mumoc airmem mes salelarap saniuqm arap

951

satsopser sa e etneilc o ednepsus on adamahc a ,onorcnssa CPR mu mE .sadubirtsid uo salelarap sarutetiuqra san rodivres e etneilc ertne etnetsixe omsilelarap o arolpxe on ele euq oledom esse a acitrc amU .eugehc

atsopser a euq otnemom o ta osnepsus etneilc o onorcns CPR mu mE

onorcnssa e onorcns soledom sO

:sotnemele ocnic ogoj me acoloc oledom essed otnemanoicnuf O

.eder ad svarta raf es ale ones ,etnemlacol raf es oacinumoc a aniuqm amsem an sodazilacol os sele eS .rodivres ,ossi od e etneilc od oazilacol ad etnemetnednepedni ed oledom

anoicnuf

ele

ro P

.setnacinumoc

sossecorp

on etnemacinu asuoper ele euq ameuqse etsed etnatropmi edadilauq amU

;etneilc ossecorp O

;rodivres ossecorp O

;aicntsid odamahc otnemidecorp O

; tneilc buts otnemidecorp O

.revres buts otnemidecorp O

061

oacinumoc ed lacol oelcn o arap megasnem a aivnE .4

megasnem a irtsnoc erudecorp A .3

osnepsus etneilc O .2

sortemrap so aivne e erudecorp a amahc etneilc O .1

:setniuges sa os lacol adamahc amu ed sapate sA .etnatsid uo lacol res edop rodivres O .adigirid megasnem a lauq oa rodivres o racificepse edop olep oirusu atief res o uo ,semon ed rodivres mu moc ,lanoicarepo od ametsis A

edop

megasnem

ad

oirtanitsed

rodivres

oazilacol

.osnepsus etneilc O .aivne a e megasnem amu me seamrofni sasse acoloc

,adamahc a ratart eved euq rodivres od e erudecorp ad oacifitnedi a atnuj ,sortemrap so agep erudecorp assE .)tneilc buts( acetoilbib ed erudecorp amu adamahc a zaf etneilc o :etniuges o adatoda oulos ad oipcnirp O .acitndi arienam ed setnatsid e siacol sadamahc sa atart onorcns CPR mU

oulos ad oipcnirp O

.otnemidecorp essed aicntsni avon amu ratucexe arap daerht avon amu ed oairc a ridepmi on euq o ,daerht amu rop oucexe me j

otnemidecorp mu ed res edop agehc euq oisiuqer avon amU .seisiuqer savon ratieca a ratlov e altart arap daerht amu rairc edop ele rodivres mu rop adibecer otnemidecorp ed adamahc adac arap ,olpmexe roP .otnemom odad mu me sadamahc

sa merof satnauq setnerrocnoc seucexe satnat ritimrep esedop omertxe ortuo assE mu mE .sadasilaires amu ed sadamahc oucexe sa an e avisulcxe res edop o oucexe mbmat

.erudecorp

levssop

omsilelarap

etsixe ,rodivres e etneilc ertne omsnorcnissa od etnemetnednepednI

.rodivres o moc olelarap me oucexe aus a aunitnoc etneilc o ,missA .airssecen os sale odnauq sadibecer os

161

lacol rodivres e etneilc ertne snegasnem ed acorT

.lacol rodivres mu adamahc amu artsom riuges a arugif A

aemocer laicini adamahc a zef euq etneilc O .71

sodatluser so iartxe tneilc buts O .61

etneilc o adroca oacinumoc ed oelcn O .51

oacinumoc ed oelcn oa atsopser ed megasnem a aivnE .41

atsopser ed megasnem a acirbaF .31

oivres oa etnednopserroc erudecorp a arapsiD .21

sortemrap so asilanA .11

megasnem a agep rodivres O .01

rodivres o adrocA .9

rodivres od snegasnem ed alif an reffub od oeredne o acoloC .8

reffub o arap megasnem ad aipc amu zaF .7

reffub mu acolA .6

)rodassecorp omsem( lacol

rodivres o

euq erbocsed e megasnem ad redaeh o asilana oacinumoc ed oelcn O .5

261

edonrepuS aniuqm A

.onorcns CPR mu ed oatnemelpmi a adahlated res spA .rodassecorp adac a lacol oelcn od e edonrepuS adanimoned ,alelarap aniuqm amu ed oircsed everb amu atief res oes atseN

oatnemelpmI

setnatsid rodivres e etneilc ertne snegasnem ed acorT

.setnatsid rodivres e etneilc ertne snegasnem ed acort amu atneserpa oxiaba arugif A

adroca o e rodivres od snegasnem ed alif an reffub od oeredne o acoloC .6

megasnem a aipoc e reffub mu acolA .5

oirtanitsed rodivres o animreted e redaeh ues asilanA .4

megasnem a ebecer oirtanitsed rodassecorp od oacinumoc ed oelcn O .3

rodivres etse a adaeredne megasnem a aivnE .2

rodivres od oacifitnedi a serodivres ed alebat aus me arucorP .1

:oacinumoc ed oelcn od oa a anerefid a ,setnatsid serodivres ed sadamahc sa otiepser zid euq oN

361

o arap adazilitu mbmat alebat atsE .otnemaetor

ed alebat amu rop adinifed

,lacol megatuor ed onuf amu rop odon adac me odarugessa ovissergorp otnemahnimacne etsE alhnimacne a ,adnuges eved an .onitsed ues oa eugehc ale euq e rodassecorp ossecorp oa ortuo mu a arap etnemairporp megasnem e ecnetrep

ele

ecnetrep eved ele

;onitsed

altimsnart

ehl megasnem a ,ariemirp an :rizudorp es medop seautis saud ,megasnem amu ed opecer ed osac oN .serodassecorp ertne uo siacol snegasnem ed otnemahnimacne e opecer alep levsnopser oacinumoc ed oelcn O

.)riuges a arugif( soirusu sod levn o e lacol oelcn o ,oacinumoc ed oelcn O :socigl sievn srt iussop rodassecorp odon adac me ador euq oelcn O

lacol oelcn O

.).cte ,lena .xe( saigolopot setnerefid ed oarugifnoc a missa odnitimrep reuqsiauq sretupsnart siod ed socisf sknil siod ratcenoc edop ,serodassecorp so ertne sacis'f sexenoc sad oazilaer alep levsnopser euq ,rodalortnoc o ,rab ssorC od osu o moC

.ohlabart ed so e elortnoc ed retupsnart o ertne oacinumoc a etimrep elortnoc ed aiv a e 27x27 rab ssorC mu seagil ed rodatumoc O .elortnoc ed aiv amu seagil ed rodatumoc mu ,siapicnirp sotnemele omoc ,adnia iussop al E .rodalortnoc ed odanimoned ,siaicepse

senuf evlovnesed euq rodassecorp mu e ohlabart ed serodassecorp 23 61 ed ret edop acisb oarugifnoc auS .retupsnarT serodassecorp rop adamrof ,mumoc airmem mes ,DMIM airogetac a ecnetrep edonrepuS aniuqm A

461

a e 1 oremn o odaicossa METSYS-ELIF rodivres oa es ,olpmexe roP .os o mbmat senuf sa ,orietni oremn mu rop odacifitnedi rodivres mu euq arienam amsem aD .ratucexe reved rodivres o euq onuf a acifitnedi onuf_oremuN ametsis on .etnemlabolg etnetsixe odicehnoc adac A ,orietni oremn o mu odaicossa rodivreS

rodivres

.rodivres

acifitnedi

.ediser rodivres o edno rodassecorp o rodassecorP .)onuf_oremuN ,rod

ivreS ,rodassecorP( rop odacifitnedi rodivres O .atsopser ad arepse a odaeuqolb tse ele lauq on orofmes o mtnoc egassem& e ediser ele edno rodassecorP .)egassem& ,rodassecorp( rop odacifitnedi etneilc O .)onuf amu ed oucexe ad sodatluser( YLPER mu uo )oivres ed odidep( DNES

mu res edop opit O .atid etnemairporp megasnem a mtnoc oproc o e rodivres od e etneilc od ,megasnem ad opit oacifitnedi a iussop redaeh O .oproc mu e redaeh mU :setrap saud me adidivid res edop )riuges a arugif( megasnem A

megasnem A

.snegasnem ed acort ed omsinacem olep e revres buts olep ,rodivres olep ,tneilc buts olep ,snegasnem ed acort e aruturtse alep adaziretcarac CPR oledom od oatnemelpmi A

odatnemelpmi CPR od oircseD

.soirusu sod seacilpa sa mador euq levn etsen mbmat .ametsis od serodivres so sodot matucexe euq soirusu levn oN

:ed searepo atnemelpmi elE .airmem ed aicnreg ed e sossecorp ed aicnreg ed senuf salep levsnopser lacol oelcn ed odamahc levn O .lacol ossecorp oa

aivne a ele ,oirrtnoc osac me ,odairporpa ohnimac olep megasnem a aivne ele ,ortuo mu onitsed rodassecorp o eS .odavita oacinumoc ed oelcn o ,etnemlacol adareg megasnem amu odnauQ .setnatsid snegasnem ed oivne

;sossecorp ed oiurtsed/oairC

;sossecorp ertne oazinorcniS

.airmem ed oarebil/oacolA

561

:otnemidecorp etniuges o matucexe serodivres sO .cte ,airmem ed aicnreg ed senuf salep reganam yromeM o ,soviuqra ed aicnreg ed senuf salep levsnopser metsy S eliF o ,olpmexe rop ,soivres ed otnujnoc mu rop levsnopser

rodivres adaC .setneilc ed sadnamed ratart ed rodivres mu ed onuf A

rodivres O

.atsopser a odnarepse odaeuqolb acif etneilc O .etnatsid rodivres o es ,oirtanitsed rodassecorp oa uo lacol rodivres oa aivne a euq oacinumoc ed lacol oelcn oa aivne a e megasnem a acirbaf erudecorp assE .sodairporpa sortemrap so moc ,tneilc buts ,acetoilbib ed erudecorp amu amahc ele ,CPR mu zaf etneilc mu odnauQ

tneilc buts O

megasnem amu ed aruturtsE

.megasnem amu ed oazinagro a artsom riuges a arugif A .mtnoc ale euq sortsiger ed oremn o e sarvalap ed oremn o megasnem an odacificepse ,osac reuqlauq mE .onuf ad adamahc ed sortemrap so meutitsnoc

e sobma uo ,sortsiger ,sarvalap rop odamrof res edop megasnem ad oproc O .7 oremn ed erudecorp a ratucexe reved euq 1 oremn rodivres ,1 oremn rodassecorp oa adaeredne megasnem amu adurtsnoc ajes euq moc raf

;)setybn ,reffub& ,rotpircsed_elif( daer = n

:adamahc a ,1 rodassecorp on adiser rodivres esse euq esodnaredisnoc ,7 oremn o DAER erudecorp

;alif ad megasnem ariemirp a rageP

;onuf a racifitnedI

661

odnauq ,).xe rop gnip( megasnem ad megiro rodassecorp od oacinumoc ed oelcn O .atsopser ad arepse a odaeuqolb tse etneilc o lauq on orofmes o acoloc ele oirtanitsed oirtanitsed ossecorp omoc ed oacifitnedi o e megiro omoC .megiro omoc ele

oirtanitsed e

acoloc

rodassecorp

agep

, ossi ,megasnem ad redaeh o etrevni ele ,spA .megasnem an adacificepse res eved edaditnauq avitcepser a ,osac reuqlauq me ,e sortsiger uo sarvalap res medop sodatluser sO .megasnem amu me acoloc so e sodatluser so agep ele ,ossi araP .atsopser ed megasnem a riurtsnoc revres buts od onuf A

revres buts O

; )(etirw_od :ETIRW esac

; )(daer_od :DAER esac

--

)noitcnof.egassem( hctiws

;)egassem(P

{ );;(rof

{ )(niam

:etniuges a ) metsys elif .xe ( rodivres mu ed lareg aruturtse A

;sortemrap ed oremn o racifireV

.etnednopserroc erudecorp a ramahC

atucexe es erudecorp A

atsopser a racirbaf arap revres buts o ramahC

atsopser a ritimsnarter arap oelcn o ravitA

761

; m& = tneilc.megiro.m

; m egassem

--

{ ) corp tni ( gnip tni

erudecorp A .ovita tse es rebas reuq es euq rodassecorp o 21 e orietni mu i edno

; ) 21 ( gnip = i

odnamoc o 5 rodassecorp on atucexe euq etneilc mu eredisnoC .ovita tse rodassecorp mu es rebas etimrep euq ,gnip selpmis adamahc amu adatneserpa res ,CPR mu ed oucexe a sehlated me siam rartsom araP

CPR ed olpmexe mU

.osufid e ) etnaeuqolb on e etnaeuqolb (otnopib ,rodivres/etneilC :ametsis on sodatnemelpmi os euq oacinumoc ed solocotorp so arap ocisb etropus o oelcn essE .ossecorp olep

sadareg os euq ,setnatsid uo siacol ,snegasnem sa raivne ed odagerracne opurg omitl essE .ossecorp adac arap amu odnitsixe ,ametsis on setnetsixe sossecorp opit soa O sadaicossa .lanac adac os a euq elortnoc daerht ed sdaerht etsixe rop odamrof

ortuo

adaicossa

amu

,oacinumoc

ed socisf sianac ortauq iussop euq retupsnarT o edonrepuS od rodassecorp o omoC .setnerefid serodassecorp ertne oacinumoc a etimrep euq e

ocisf lanac od snegasnem sa ebecer euq mU .sdaerht ed o n r ot me odazinagro oelcn

:sdaerht ed sopit siod metsixE essE .oacinumoc ed oelcn

o ametsis on snegasnem ed acort a atropus euq esab ed omsinacem O

snegasnem ed acort ed omsinacem O

.)orofmes on V oarepo( etneilc ossecorp o raeuqolbsed ,osac essen ,e atsopser omoc racifitnedi a megasnem asse rebecer

861

; ) corp.tsed>m (etuor_teg = ocisif_lanac

/* olpmexe etsen 5 */ ; rebmun-ym = corp.megiro.m

; ) m ,lennahc ( ni

atucexe adavita euq daerht A .megasnem an etsixe euq orofmes on P

oarepo a moc ,odaeuqolb etneilc o ,riuges A .oacinumoc ed oelcn o arap ossecorp od adaivne megasnem a ,missA .daerht a avita e megasnem ad oeredne o ocigl lanac on acoloc ) m&, lennahc ( tuo ourtsni A .lanac essen tuo oarepo alep adavita ale e )ni oarepo ( lanac essen megasnem amu ed arepse a erpmes acif daerht A .sedaditne saud sasse a labolg ocigl lanac mu ed svarta atief elortnoc ed daerht aus a e ossecorp A .oacinumoc ed oelcn oa ecnetrep euq e o ertne oacinumoc aus ed odnauq

oairc

adaicossa ehl euq elortnoc ed daerht amu iussop ametsis on ossecorp adaC . tuo oarepo a moc oacinumoc ed oelcn o avita ale ,otnE .)DNES( megasnem ad opit o e rodivres o ,rodassecorp o macifitnedi euq sopmac so atelpmoc ale sioped ,megasnem ad oeredne o acoloc ale tneilc.megiro.m mE .seamrofni sartuo moc e sodibecer sortemrap so moc atelpmoc

ale lauq a ,)m( megasnem aruturtse

amu acola alE

.megasnem a acirbaf

; ) orofames.m ( P

; ) m& , lennahc ( tuo

; DNES = epyt_egassem.m

; GNIP = noitcnof.tsed.m

; METSYS = ruevres.tsed.m

; 21 = corp.tsed.m

961

ele

snegasnem

ed

alif

amu

ed

oeredne

,seamrofni

sartuo

ertne

,mtnoc euq rotircsed ortsiger mu rop otircsed ametsis on rodivres adaC .reffub mu me acoloc a e ocisf lanac od megasnem a l daerht a etnemlaicinI

--

:METSYS_ELIF esac

:REGANAM_YROMEM esac

; kaerb

; ) orofames.]METSYS[ruevres_ruetpircsed (V

rodivres od alif an megasnem a acoloc

-- :METSYS esac

--

) ruevres.tsed.reffub ( hctiws

; ) m ,ocisif_lanac ( ni = reffub

:atucexe aeredne a 5 rodassecorp o lauq od ritrap a lanac olep magehc euq snegasnem sa ebecer euq oacinumoc ed oelcn od daerht A .21 rodassecorp od oacinumoc ed oelcn on agehc e serodassecorp ed e d er a assevarta megasnem A .) m ,ocisif_lanac(tuo

oarepo a moc lanac esse rop megasnem a aivne e levsseca )21( onitsed rodassecorp o lauq od ritrap a ocisf lanac o mtbo etuor-teg onuf ad osu o moc ,spA .oelcn od odicehnoc e adac a odubirta ocigl oremn toob ed esaf ad odnauq rodassecorp rodassecorp od oacifitnedi

,megiro

a moc megasnem a atelpmoc daerht A .megasnem a ebecer ni oarepo A

; ) m ,ocisif-lanac ( tuo

071

ourtsni alep odazilobmis ,megasnem a agep ele ,V oarepo ad oa alep ,aemocer METSYS rodivres o odnauQ

; kaerb

; ) egassem& ,lennahc ( tuo

; egassem& = ruevres.tsed.egassem

; corp.megiro.m.egassem = corp.tsed.egassem

; 1 = ylper_gsm.egassem

; YLPER = epyt.egassem

:GNI P esac

--

) noitcnof.egassem( hctiws

; m.]METSYS[ruevres_ruetpircsed = egassem

; ) orofames.]METSYS[ruevres_ruetpircsed (P

{ );;( rof

--

{ )( metsys

:etniuges o rodivres od ogidc O

.orofmes ues me V oarepo a moc adroca o e METSYS rodivres od alif an megasnem a acoloc daerht A .METSYS rodivres o evercsed

serotircsed ed yarra on ]METSYS[ruevres_ruetpircsed adartne A .megasnem amu ed arepse a odaeuqolb acif ele lauq on orofmes mu e sadaeredne

171

o adroca ele ,osac etseN .atsopser omoc ecehnocer a e megasnem a ebecer ) 5 ( megasnem ad oirnigiro rodassecorp od oacinumoc ed oelcn O

lacol megasnem amu arap

esle

; ) egassem ,ocisif_lanac ( tuo

; ) corp.tsed>egassem (etuor_teg = ocisif_lanac

{ ) rebmun_ym = ! corp.tsed.egassem ( fi

/* olpmexe etsen 21 */ ; rebmun_ym = corp.megiro.egassem

; ) egassem ,lennahc ( ni

.sea sasse a ednopserroc euq daerht ad ogidc ed otnemgarf o odatneserpa riuges A .megasnem a aivne e

) corp.tsed>m (etuor_teg = ocisiflanac

levsseca rodassecorp esse lauq od ritrap a ocisf lanac o mtbo ele ,) 5 ( ortuo mu osac etseN .oirtanitsed rodassecorp o asilana e megiro omoc rodassecorp od oacifitnedi a odnacoloc megasnem a atelpmoc elortnoc ed daerht A

.elortnoc ed daerht aus a aieuqolbsed euq tuo oarepo a moc oacinumoc ed oelcn oa aivne a e megasnem ad oeredne o acoloc ele oirtanitsed rodivres omoC o .megiro ,missA oirtanitsed o e oirtanitsed an anrot o es megiro

rodassecorp

.lanigiro

megasnem

rodassecorp

macifitnedi

euq sopmac so etrevni e GNIP od oucexe an ossecus odnacidni ylper_gsm

opmac on 1 ,opit omoc YLPER odnacoloc megasnem a acirbaf ele ,otnE .atsopser a raivne me etnemacinu etsisnoc ,selpmis otium onuf a GNIP mu ed osac oN .onuf a acifitnedi e )m.]METSYS[ruevres_ruetpircsed = egassem

271

:arap senuf enifed IPM ordap O

.amargorp od ohcert mu oucexe arap odanoiceles rodassecorp adac me e oucexe ad setnapicitrap serodassecorp sod mu adac me odarapsid amargorp omsem mu lauq on ,DMPS oledom o odnazilitu ramargorp ed larutan amrof amu ,otnatne oN .DMPM oamargorp ed oledom o aziretcarac euq o ,etnerefid amargorp mu ratucexe edop sossecorp sessed mu adaC .rodassecorp rop ossecorp mu odairc euq odnes ,oazilaicini ad otnemom on sodairc ,sossecorp ed oxif otnujnoc mu rop odamrof IPM amargorp mU nartroF uo CISNA me sotircse samargorp ed ritrap a odazilitu res edop sanitor ed otnujnoc etsE .snegasnem rebecer e raivne arap acetoilbib ad sanitor odnamahc macinumoc es euq sossecorp siam uo mu edneerpmoc oucexe amu IPM mE .oamargorp ed ecafretni ad sacinct seacificepse sa mtnoc e ,4991 ed oiam me levnopsid uonrot es ,murF IPM on adinifed ,0.1 osrev A .asiuqsep

ed soirtarobal ,saserpme ,sedadisrevinU ed oapicitrap a moc ,)gro.murof -ipnm.www( murF IPM olep adinifed ioF .snegasnem ed acort me adaesab alelarap oamargorp a etimrep euq oacinumoc ed acetoilbib amu IPM

a ogidc O .odaeuqolb avatse ele euq orofmes on V oarepo a moc etneilc

5.4 Estudo de caso: Message Passing Interface - MPI


rodivres mu rap oivres ed odidep mu esle ; ) orofames.m ( V ) YL PER = = epyt. m ( fi ; ) m ,ocisf-knil ( ni .atsopser ad opecer a atneserpa riuges

371

:sortemrap srt rop otsopmoc .)onitsed uo megiro( oerednE

:setrap saud rop adamrof ,oacinumoc amu ed odetnoc o

megasneM
.etneibma od oarugifnoc an adacificepse serodassecorp ed atsil a moc odroca ed ,etnemralucric ,sodairc os sossecorp so ,odacificepse oremn o euq ronem socisf serodassecorp ed oremn o eS .oucexe me )samargorp( sossecorp ed oremn o acidni amargorp od oucexe a arapsid odnauq oirusu olep odacificepse serodassecorp ed oremn o ,amrof atseD .ossecorp mu iutitsnoc es oucexe me amargorp adaC

ossecorP
.IPM socisb sotiecnoc snugla sodatneserpa ores riuges A

.IPM acetoilbib alelarap oamargorp ed sacitsretcarac savon aroprocni euq 7991 me adinifed osrev ,2-IPM ed sacitsretcarac siapicnirp sa e IPM me sotircse samargorp ed solpmexe sodatneserpa mbmat oreS .samargorp ed otnemivlovnesed o etimrep senuf ed odizuder oremun mu siam moc etnematnuj ,euq otnop a otnop oacinumoc ed sacisb senuf sa sadatneserpa ores otnemucod etseN .samelborp ed edadeirav

ednarg amu revloser levssop )6 sanepa( odizuder oremn mu moc ,otnatne oN .)921( senuf ed otnujnoc emrone mu iussop IPM ed 1.1 osrev A

;otnop a otnop oacinumoC

;saviteloc searepO

;sossecorp ed sopurG

;oacinumoc ed sotxetnoC

;77 nartroF e C ISNA samargorp arap oagiL

.sossecorp ed aigolopoT

Conceitos bsicos

epolevnE

471

amu ed oirtanitsed ossecorp o racifitnedi arap odazilitu .sossecorp ed oremn o N edno ,1-N ta orez ed odnaemoc ,orietni oremn mu rop adatneserper auntnoc oacifitnedi assE .odazilaicini ossecorp o odnauq ametsis olep adubirta acin oacifitnedi amu met ossecorp o odoT

knaR
tni trohs dengiS rahc dengisnU tni gnol dengiS elbuod gnol tni gnol dengisnU tni dengisnU tni trohs dengisnU elbuoD taolf tni dengis rahc dengis C on oinifeD DEKCAP_IPM ETYB_IP M TROHS_IPM RAHC_DENGISNU_IPM GNOL_IP M ELBUOD_GNOL_IPM GNOL_DENGISNU_IPM DENGISNU_IPM

C on socisB sodaD ed sopiT

:sotnemugra srt rop odatneserper .rebecer uo raivne ajesed es euq oamrofnI

;)rotpecer e rossimsnart( sossecorp sod oacifitnedI

;megasnem ad olutR

.rotacinumoC

odaD

;azilacol es odad o edno oerednE

;megasnem an odad od sotnemele ed oremN

:os C megaugnil an sodad ed sopit sO

MPI_UNSIGNED_SHORT
ELBUOD_IPM TAOLF_ I PM TNI_ I PM RAHC_IPM IPM on oinifeD .odad od opiT

571

.opurg on ossecorp o acifitnedi o acidni

dip& e

oacinumoc ed opurg

rotacinummoc .etnerroc ossecorp od rodacifitnedi o animreteD

)dip& , rotacinummoc(knaR_mmoC_IPM
.opurg on sossecorp ed oremn o ,avitimirp ad oucexe ad onimrt oa ,mtnoc ezis& e oacinumoc ed opurg o acidni

rotacinummoc .oucexe amu me sossecorp ed oremn o animreteD

)ezis& , rotacinummoc(eziS_mmoC_IPM
.IPM amargorp mu me onuf amitl a res eveD .IPM oucexe amu animreT

)(ezilaniF_IPM
Inicializa uma execuo em MPI, responsvel por copiar o cdigo do programa em todos os processadores que participam da execuo. Nenhuma outra funo MPI pode aparecer antes de MPI_INIT. argc, argv so variveis utilizadas em C para recebimento de parmetros.

)vgra& , cgra&(tinI_IPM

.IPM ed sacisb savitimirp sa sadatneserpa ores riuges A

.)sodaeredne res medop euq sossecorp ed otnujnoc( oacinumoc amu ed )otxetnoc( oinmod o atneserper euq lacol otejbo mu rotacinummoc O

.rotacinummoc mu moc puorg mu ed sorbmem os sossecorp so sodot ,etnemlaicinI ."DLROW_MMOC_IPM" omoc odinifederp j sezev satium rotacinummoc mu a odaicossa puorg reuqlauq e odoT .sossecorp N ed odanedro otnujnoc mu puorG

,megasnem amu ed etnetemer ossecorp o e ,dnes oarepo an ,megasnem

Primitivas Bsicas MPI


rotacinummoC puorG
.eviecer oarepo an

671

/* ossecorp od rodacifitnedI */ ;knar_ym tni { )vgra **rahc ,cgra tni(niam "h.ipm" edulcni# >h.oidts< edulcni#

.emirpmi a euq ,ortuo mu arap megasnem amu aivne ossecorp mu lauq on ,selpmis amargorp mu odatneserpa res riuges A

amargorp ed olpmexE
oarepo ed sutats :

sutats mmoc gat

oacinumoc ed opurg:

megasnem ad opit : megasnem ad etnetemer ossecorp od rodacifitnedi : sodaivne meres a sotnemele sod opit :

tsed

epytatad tnuoc fub&

raivne a sotnemele ed oremn :

otnemibecer ed reffub od oeredne :

:os sortemrap sO .megasnem ad otnemibecer o ta odaeuqolb acif atucexe a euq ossecorp O .etnaeuqolb oarepo amu .snegasnem ed otnemibecer olep levsnopser onuF

)mmoc ,gat ,tsed ,epytatad ,tnuoc ,fub&( vceR_IPM


oacinumoc ed opurg:

mmoc gat

megasnem ad opit : megasnem ad onitsed ossecorp od rodacifitnedi : sodaivne meres a sotnemele sod opit :

tsed

epytatad tnuoc fub&

raivne a sotnemele ed oremn :

oivne ed reffub od oeredne :

Permite a um processo enviar uma mensagem para um outro. uma operao no bloqueante. O processo que a realiza continua sua execuo. Os parmetros so:

)mmoc ,gat ,tsed ,epytatad ,tnuoc ,fub&( dneS_IPM

771

atsiuqnoc e osiviD
:os seacilpa saus ed otnemivlovnesed o arap rodamargorp olep sodazilitu res medop euq soledom sO .oluclc mu ed ouloser a arap marepooc euq e setnerefid serodassecorp me matucexe euq setnacinumoc sossecorp rop otsopmoc olelarap amargorp mU

.emirpmi a e ,vceR avitimirp ,megasnem a ebecer 1 ossecorp O .dneS avitimirp a moc 1 ossecorp o arap ola odnetnoc megasnem amu aivne

0 ossecorp O .)sossecorp siod rop odatucexe res arap ( animret amargorp o 2 ed etnerefid rof sossecorp ed oremun o es e )knar_ym( oacifitnedi aus mtbo ossecorp adaC .sossecorp siod rop odamrof amica amargorp O

,DLROW_MMOC_IPM ,99 ,0 ,RAHC_IPM

,99 ,1 ,RAHC_IPM

; )n& ,DLROW_MMOC_IPM(eziS_mmoC_IPM ; )knar_ym& ,DLROW_MMOC_IPM(knaR_mmoC_IPM ;)vgra & , cgra&(tinI_IPM

Modelos de programas paralelos


} ;)(ezilaniF_IPM } ; )c , n\s % (ftnirP ; )sutats ,5 ,c( vceR_IPM { esle ; )DLROW_MMOC_IPM ,)c( nelrts ,c( dneS_IPM ; ) ola ,c( ypcrts { )0 == knar_ym( fi ; )(tixe )2 =! n( fi ; sutats sutatS_IPM ; ]5[c rahc /* sossecorp ed oremN */ ;n tni

871

.etniuges esaf rassap arap siamed solep erepse ossecorp mu euq arap sodasu os )sarierrab .xe( oazinorcnis ed somsinaceM .etniuges esaf a rassap arap esaf amu menimret sossecorp so sodot euq oirssecen odnes ,sesaf rop odamrof olelarap amargorp O

salelarap sesaF
.odatucexe ajes saferat ed otnujnoc o euq ta eteper es esaf atsE .atucexe e aferat amu ed etrap amu ariter ossecorp adaC .olelarap amargorp od setnenopmoc sossecorp soa levsseca aer amu me odatisoped saferat ed otnujnoc mU

ohlabart ed looP
.ovarcse o arap aferat avon amu aivne euq ,ertsem oa sodatluser so aivne e aferat aus atucexe ovarcse adaC .)sovarcsE( sossecorp siamed so ertne etnatser o edivid e aferat ad etrap atucexe euq )ertseM( ossecorp mu rop odamrof odnes omoc odazinagro amargorp O

ovarcse/ertseM
.enilepip on etniuges ossecorp o arap aivne e assecorp ,adibecer megasnem amu ed sodad so iartxe rodebecer ossecorp O .retemer e sodad so rapurga eved etnetemer ossecorp o ,rodassecorp ortuo mu erbos ossecorp mu a sodad raivne araP .ountnoc oxulf mu me seamrofni ed acort a moc ,enilepip mu mamrof sossecorp ed otnujnoc mU .snegasnem ed acort rop marepooc sossecorp sO

enilepiP
.iap ossecorp oa sodatluser so mevloved e matucexe sohlif sO .aferat amu ed seronem setrap ratucexe arap sohlif sossecorp ed oairc an etsisnoc acinct a tsE

include "mpi.h" main(argc,argv) int argc; char **argv; { int numero, i, fat=1 ; int myrank, size; MPI_Status status; MPI_Init (&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&myrank); MPI_Comm_size(MPI_COMM_WORLD,&size); if (myrank==0){ printf("Sou o processo 0 \n"); for(i=1; i<4; i++){ scanf(%d, &numero); printf("Numero: %d \n",numero); MPI_Send(&numero,1,MPI_INT,i,99,MPI_COMM_WORLD); } for(i=1; i<4; i++){ MPI_Recv(&numero,1,MPI_INT,MPI_ANY_SOURCE,99,MPI_COMM_WOR LD,s&tatus); printf("resultado: %d \n",numero); } } else { if (myrank==1) { printf("Eu sou o processo 1 \n"); MPI_Recv(&numero,sizeof(int),MPI_INT,0,99,MPI_COMM_WORLD, &status); for(i=1; i<numero; i++) fat = fat*i ; MPI_Send(&fat,1,MPI_INT,0,99,MPI_COMM_WORLD); } else { if (myrank==2) { printf("Eu sou o processo 2 \n"); MPI_Recv(&numero,sizeof(int),MPI_INT,0,99,MPI_COMM_WORLD, &status); for(i=1; i<numero; i++) fat = fat*i ; MPI_Send(&fat,1,MPI_INT,0,99,MPI_COMM_WORLD); } else{ printf("Eu sou o processo 3 \n");

o moc mu ,samargorp siod sodatneserpa ores riuges A .sodatneserpa amica 971 so arap aivne ,serolav mtbo )ertsem o( ossecorp mu riuges a amargorp oN .emirpmi so e soluclc so ebecer ,lairotaf a meraluclac .enilepiP mu ortuo e ovarcsE/ertseM oledom ovarcse/ertsem amargorP sovarcse

soledom

sod

es-odnazilitu

samargorp

rarobale

levssop

IPM

moC

MPI_Recv(&numero,sizeof(int),MPI_INT,0,99,MPI_COMM_ WORLD,&status); for(i=1; i<numero; i++) fat = fat*i ; MPI_Send(&fat,1,MPI_INT,0,99,MPI_COMM_WORLD); } } } MPI_Finalize(); }

#include "mpi.h" main(argc,argv) int argc; char **argv; { int numero; int myrank, size; MPI_Status status; MPI_Init (&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&myrank); MPI_Comm_size(MPI_COMM_WORLD,&size); printf("Ola... \n"); if (myrank==0) { printf("Sou o processo 0 \n"); scanf(%d, &numero); MPI_Send(&numero,1,MPI_INT,1,99,MPI_COMM_WORLD); MPI_Recv(&numero,1,MPI_INT,2,99,MPI_COMM_WORLD,&status); printf("Sou o processo 0, recebi do processo 2 o valor%d \n", numero); } else { if (myrank==1)

081

.sovarcse srt e ertsem o :sossecorp ortauq rop odamrof amica amargorp O ed otnemibecer o etimrep euq ,ECRUOS_YNA_IPM moc atief etnetemer od odatluser etse aivne e odibecer oremn od lairotaf a aluclac ,)vceR avitimirp( oacifitnedi a ,vceR avitimirp ,sodatluser sod otnemibecer o araP .sovarcse a moc ,ovarcse adac arap mu aivne e ertsem od rolav o ebecer ovarcse adaC sod soluclc solep odnarepse oal mu me acif riuges a ,dneS avitimirp .enilepip mu ed olpmexe o atneserpa riuges a amargorp O .ossecorp reuqlauq ed snegasnem enilepiP amargorP .ertsem o arap serolav srt ed arutiel a zaf ertsem O

{ printf("Eu sou o processo 1 \n"); MPI_Recv(&numero,sizeof(int),MPI_INT,0,99,MPI_COMM_WORLD, &status); numero = numero + 10 ; MPI_Send(&numero,1,MPI_INT,2,99,MPI_COMM_WORLD); } else { printf("Eu sou o processo 2 \n"); MPI_Recv(&numero,sizeof(int),MPI_INT,1,99,MPI_COMM_WORLD, &status); numero = numero + 10 ; MPI_Send(&numero,1,MPI_INT,0,99,MPI_COMM_WORLD); } } MPI_Finalize(); }

No programa acima so criados trs processos. O processo 0 obtm um valor e o envia para o processo 1. O processo 1 adiciona um outro valor ao recebido e envia ao processo 2, que adiciona um valor ao recebido e envia para o processo seguinte no pipeline, que no caso o processo inicial (0).

Compilao e execuo de programas


o moc atief ) ++C( C 181 megaugnil an sotircse samargorp ed oalipmoc A sievnopsid sepo sa sadot artsoM odnamoc o moc atief oucexe A .C rodalipmoc odnamoc saniuqm sad emon o mtnoc euq oviuqra o acificepsE - elifenihcam od oalipmoc ed sotnemugra so sodot atieca ccipm odnamoc o edno sodatucexe odnes otse sossecorp so edno artsigeR )s(aniuqm )s(ad arutetiuqra a acificepsE serodassecorp ed oremn o acificepsE -

]sortemrap[ ]levtucexe[ o- ]c.etnof[ ccipm


)s(aniuqm )s(a acificepsE -

]levtucexe[ ]sotnemugra[- nuripm


:os sotnemugra sO gp_evael enihcam hcra pn h

281

.IPM sotejbo etnerapsnart siam ranrot arap

.saviteloc searepo savon riurtsnoc ed sodotm sovon

e srotacinumocretni

.oalumuca ed satomer searepo e )tup/teg( adahlitrapmoc airmem ed searepo meulcni satsE

.ossecorp

ocin mu rop sadazilaer os euq oacinumoc ed searepo sadinifed os

:etnapicitrap ocin mu moc oacinumoC

.sossecorp ed acimnid oairc a metimrep

:metimrep sedadilanoicnuf savon satsE .oatupmoc ed soledom soa osnetxe amu odnitimrep ,IPM sedadilanoicnuf savon anoicida 2-IPM .2-IPM enifed ,serdap sues ratneserpa e 2.1 IPM revercsed .ordap IPM

ed mla ,euq otnemucod mu odacilbup iof 7991 ed ohluj mE oa

sesnetxe e seerroc raredisnoc a uoemoc IPM muroF o 5991 edseD

.4nus arutetiuqra ed serodassecorp 5 me etset amargorp o atucexE etset 5 pn- 4nus hcra- nuripm serodassecorp 5 me etset amargorp o atucexE etset 5 pn- nuripm

:solpmexE

xbd o erbos ossecorp oriemirp o azilaicinI -

odatucexe res euq o emirpmi sanepa ,amargorp o ratucexe mes atseT lacol aniuqm an atucexe oN t

lacolon

MPI-2

euq savitimirp sadinifed os

:sossecorp ed aicnreg e oairC

:saviteloc searepo s sesnetxE

xbd

,IPM ed amica ,levn ovon mu odinifed

:sanretxE secafretnI

Concluso
on rotiel o raicini ovitejbo omoc met odatneserpa IPM ed odutse O

[PAC97]

381

sa ,IPM me sodazilitu socisb sotiecnoc sodatneserpa maroF .oacinumoc

Bibliografia
[BLA90] BLACK, D. L. Scheduling support for concurrency and parallelism in the Mach operating system. Computer. V. 5(23). May, 1990. CAVALHEIRO, G. G. H. Introduo programao paralela e distribuda. In: Anais I Escola Regional de Alto Desempenho. Gramado. 2001. FOSTER, YAN. Designing and Building Parallel Programs. Addison Wesley, 1995. GEIST, Al et al. PVM: Parallel and Virtual Machine- A User s Guide and Tutorial for Networked Parallel Computing. London: MIT, 1994 MPI-10 disponvel em http://www.mpi-forum.org , May 1994. MPI-2 disponvel em http://www.mpi-forum.org , May 1994. OLIVEIRA, R. S de; CARISSIMI, A. S e TOSCANI, S. S. Sistemas Operacionais. Porto Aleger: Sagra-Luzzatto. 2001 PACHECO, PETER. Paralllel Programming with MPI. Morgan Kaufmann Publischers, 1997.

[CAV01]

[FOS95]

[GEI94]

[MPI94] [MPI97] [OLI01]

ed oagil ed sacitsretcarac savon sadinifed os :

ritimrep a arienam ed )enilepip e ovarcse/ertsem( oamargorp ed soledom

siod me samargorp ed

e razilaicini arap e snegasnem ed acort arap sadazilitu senuf siapicnirp

ed acetoilbib atsed osu o moc solelarap samargorp ed otnemivlovnesed

solpmexe sodatneserpa maroF .ametsis o razilanif

.09-nartroF moc e ++C moc IPM

snegaugniL

O/I arap etropus ed somsinacem sodinifed os

.IPM on olelarap .osneerpmoc licf amu

:olelaraP O/I

[POW91]

POWELL, M. L. et al. SunOS multi-thread architecture. In. Proc. of the Winter 1991 USENIX Technical Conference and Exhibition. Springer Verlag, LNCS 980. 1991. PVM Home Page disponvel em http://www.epm.ornl.gov/pvm/pvm_home.html , Nov. 2001 SEBESTA, R. W. Conceitos de linguagens de programao. Porto Alegre: Bookman. 2000.

[PVM 01] [SEB00]

Exerccios Bibliografia

481

581

:kcoldaed ed ocisslc olpmexE

sodarebil ores siamaj euq sosrucer ed arepse sodaeuqolb otse sossecorp lauq an oautis amu

kcoldaeD

acitrc oiger

airmeM

S/E ed sovitisopsiD

:sosrucer ed .xE .ossecorp mu rop odatisiuqer e levnopsid tse on osrucer mu odnauq erroco oieuqolb mU .sossecorp ed oieuqolb ranoisaco meredup euq sedaditne reuqsiauq oS

.somsem solep odnitepmoc sossecorp ed oremn mu ertne odubirtsid res a sosrucer ed otinif oremn mu ed etsisnoc ametsis mU

ametsis ed oledoM

.kcoldaeD rativE .kcoldaeD ed oneverP .kcoldaed ed oarepucer e oceteD .kcoldaeD ed soipicnirP

Recursos

6.1 Princpios de Deadlock

6. Deadlock

681

.avisulcxe etnemautum amrof ed osu arap osrucer o aticilos ossecorp o :autm osulcxE )1

.]1791 ,syevruS gnitupmoC MCA

.skcoldaeD metsyS

.la .te ,namffoC[ kcoldaed ed aicnrroco a arap sairssecen seidnoC

)oazinorcnis ed sanis ,snegasnem ed sacort( setnarepooc sossecorp ed sametsis sod sacitsretcarac oS .serodimusnoc sodanimoned os sedadinu sa memosnoc euq sossecorp so e serotudorp sodanimoned os sedadinu sa mezudorp euq sossecorp sO .sossecorp solep etnemacimanid sadimusnoc e sadairc os euq sedadinu ed odairav oremn mu rop sodutitsnoc oS

sievmusnoc sosruceR

.levnopsid ,adacola :sodatse setniuges sod mu me ratse edop edadinu adaC .laires amrof ed ,ortuo rop adazilituer res edop ,ossecorp mu rop adazilitu odis ret edadinu amu spA .siamed sad etnednepedni amrof ed adazilitu res odnedop amu adac ,sacitndi sedadinu ed oxif oremn mu ed sodutitsnoC

sievsuer etnemlaireS

.odarebil res acnun euq osrucer mu ed arepse a sodaeuqolb oracif 2R 2P otnauq 2P 1P otnat o siop ,kcoldaed me o artne retbo ametsis ed setna o e ,))2R(R( ))1R(R(

eriuqda

ossecorp

,osrucer

odnuges

1R osrucer oriemirp o eriuqda 1P ossecorp o es ,olpmexe oN .matissecen euq osrucer oriemirp o meriuqda sossecorp siod so odnauq erroco kcoldaed O

)2R,1R(L ... ;)1R(R ... ;)2R( R ... :2P

)2R,1R(L ... ;)2R(R ... ;)1R( R ... :1P

.oxiaba odartsom omoc ,1R sosrucer so etisiuqer e sea samugla etucexe ,2R osrucer o etisiuqer 2R ossecorp o euq e 2R osrucer o etisiuqer e sea samugla etucexe ,1R osrucer o etisiuqer 1P ossecorp o euq odnopuS

Tipos de recursos

781

oisiuqer oacola 2P

1P R oacolA R

.iR osrucer od edadinu amu adacola iussop ossecorp o euq acifingis iP ossecorp mu arap iR osrucer od atsera amU .iR osrucer od edadinu amu ed oaticilos a acifingis iR osrucer mu arap iP ossecorp mu ed atsera amU

oatneserpeR

sodacola otse euq sosrucer ed arepse odaeuqolb tse ossecorp adac lauq on olcic mu ed oamrof a levssop rof odnauQ :ralucric arepsE )4

.sossecorp sortuo a sodacola meres arap etnemairaropmet sodacsifnoc res meredup on sosrucer so odnauQ :opmeerp oN )3

marepse otnauqne sosrucer meussop sossecorP

6.2 Detectar e recuperar deadlocks


skcoldaed rativE -3 rineverP -2 rarepucer e ratceteD -1 kcoldaed ed otnematart arap sodotM .olcic omsem ed sossecorp sortuo arap .sianoicida sosrucer rop :sosrucer rop arepsE )

881

kcoldaed me otse euq so os sodizuder res medop on euq sossecorp sO

saditnarag res medop ossecorp od seisiuqer sa sadot es ossecorp mu a oaler me odizuder res edop ofarg mU etsixe es ranimreted arap sofarg ranimaxe ed selpmis kcoldaed amu

arienam

sofarg ed oudeR

sadidneta ores acnun sossecorp snugla arap seisiuqer sa es kcoldaed etsixE

.kcoldaed mu etsixe es ranimreted ,sofarg sod esilna alep ,levssop

.osrucer omsem etsed sedadinu saud odnaticilos tse 1p e ,adacola 0R osrucer od edadinu amu iussop 2P

2P

1P

0R

,oxiaba arugif aN .0R osrucer od sedadinu saud odnaticilos tse e 1R osrucer od edadinu amu iussop 2P ossecorp O .adacola 0R osrucer od edadinu amu iussop 1P ossecorp o ,amica arugif aN

981

sedadinu satium moc osrucer ocin mu araP

kcoldaed ed oceted ed omtiroglA

.kcoldaed me artne on ametsis o e matissecen euq ed sosrucer so ririuqda medop sossecorp so ,otnatroP .sadidneta seisiuqer saus ret aroga edop 2P

2P

1P 1R 0R

ossecorp o arap/ed satsera sa es-odnariter atief ouder a saditnarag res medop seisiuqer saus euqrop 1P rop ofarg o rizuder somedoP

2P

2R

1P

1R

levtuder etnematelpmoc ofarg o es etnemos e es kcoldaed me sossecorp etsixe oN

:ameroeT

091

} } ;)P(cola + liava =: liava ;eurt =: noitcuder ;1+ ssecorpdecuder =: ssecorpdecuder ;eurt =: )P(decuder { neht )liava =< )P(qer( fi { ))P(decuder ton( fi { )ssecorpforebmun ot 1 = P ( rof ;eslaf =: noitcuder noitcuder ton nehw tixe pool rizuder levssop siam ajes on euq ta ritepeR ;0=:ssecorpdecuder ,eslaf =: )i(decuder )ssecorpforebmun ot 1=i( rof nigeb
sievnopsid etnemetneserp sedadinu ed oremn :LIAVA

omtiroglA

.sievnopsid

;ossecorp

sodad ed saruturtse

adac arap sairssecen sedadinu ed oremn o atneserper euq rotev

osrucer od sedadinu ed oremn o atneserper euq ,arietni levirav

191

osrucer rop sedadinu sairv moc sosrucer soirv arap omtiroglA

0 oacolA 0 0

0 0 1

0 1 1

2P 1P 0P

0 1 1

0 0 0

1 0 0

2P 1P 0P

oisiuqeR

liavA

2R

1R

0R

.sievnopsid etnemetneserp ,osrucer adac ed ,sedadinu ed oremn o atneserper euq rotev : liava

ossecorp adac a sadacola etnemetneserp ,osrucer adac ed ,sedadinu sa atneserper euq zirtam : colla

sossecorp sod seisiuqer sa atneserper euq zirtam

: qer

osrucer rop sedadinu sairv moc sosrucer soirv arap omtiroglA

;dne ;)ssecorpforebmun = ssecorpdecuder( =: decuderyletelpmoc pool dne }

291

)++R ;secruosserforebmun

=< R ;1 = R( rof

;eurt =: noitcuder ;1+ ssecorpdecuder =: ssecorpdecuder ;eurt =: )P(decuder


{ )pybdecuder( fi

;eslaf =: pybdecuder

{ neht )R(liava > )R()P(qer fi

{ )++R ;secruosserforebmun

=< R ;1 = R( rof

eurt =: pybdecuder

{ ))P(decuder ton( fi { )ssecorpforebmun ot 1 = P ( rof ;eslaf =: noitcuder ;noitcuder ton nehw tixe pool rizuder levssop siam ajes on euq ta ritepeR ;0=:ssecorpdecuder ,eslaf =: )i(decuder )ssecorpforebmun ot 1=i( rof nigeb
.sedadinu N odniussop osrucer adac e sosrucer N moc ametsis mu odnaredisnoc kcoldaed ed aicnrroco a atceted e ,etnemroiretna odatneserpa od osnetxe amu riuges a omtirogla O

391

.sodad ed esab ed oazilauta .xe levssop erpmes men

:missA .odanimile ossecorp

sossecorp ed oanimreT )a

:sievssop os sea satium ,kcoldaed mu ed aicntsixe a animreted kcoldaed ed oceted ed omtirogla o odnauQ

kcoldaed ed oarepuceR

.sosrucer ed arepse a opmet otium h

:omtirogla o ratucexe odnauQ

;)ssecorpforebmun = ssecorpdecuder( =: decuderyletelpmoc pool dne } }

;)R()P(cola + )R(liava

=: )R(liava

;atiefsitas res edop on oisiuqer amu odnauQ

odaeuqolb tse ossecorp mU :xE kcoldaed ed atiepsus etsixe odnauQ

od oucexeer me acilpmi oa atsE .sossecorp so sodot ranimreT

;odanimile ajes kcoldaed o euq ta zev rop amitv amu rehlocse

;odanimret res a ossecorp o

etnemasoiretirc rehlocse

o
;dne

.oceted ed omtirogla o ratucexeer

:ossecorp mu ed oucexeer ad amelborP

491

etnemaviteloc sodot raticilos otne ,e odnazilitu avatse euq so rarebil eved levnopsid on osrucer mu ratisiuqer odnauq sam ,sosrucer rarebil e ratisiuqer edop ossecorp mU .sianoicida sosrucer rop marepse

.zev acin amu me atissecen euq sosrucer so sodot aticilos ossecorp o es adanimile oidnoc atsE .avisulcxe etnemautum amrof ed osu arap osrucer o aticilos ossecorp o :autm osulcxE )1

.aicnrroco aus arap sairssecen seidnoc sad amu sonem

olep

es-odnanimile

kcoldaed

ed

seautis

es-eniverp

,otnatroP

.kcoldaed

ed

aicnrroco

edepmi

oidnoc

amu

ed

aicnsua

.rerroco

kcoldaed

mu

arap

setneserp

ratse

meved

seidnoc

ortauq

sa

,namffoC

odnugeS

;osrucer mu ridep

;)sosrucer ,airmem ed megami( oviuqra mu me odavarg

kcablloR )c

.amitv ad ahlocse a arap soirtirc ed oinifed a odivloser res a amelborp O .odanimile ajes kcoldaed o euq ta ,olcic omsem on ,sortuo a seugertne e olcic on sossecorp ed sodariter os sosruceR

sosrucer ed opmeerP )b

odatse o ,etnemacidoirep ,euq me stniopkcehc meussop sossecorp sO

ed setna ta kcabdellor ossecorp o ,odatceted kcoldaed mu odnauq

.olcic on ossecorp ortuo mu a odubirta osrucer o

6.3 Prevenir a ocorrncia de deadlocks

otnauqne

sosrucer

meussop

sossecorP

.:sosrucer

rop

arepsE

591

kcoldaed ed odatse mu oruges on odatse odot meN

oruges on odatse mu kcoldaed ed odatse O

aruges aicnqes amu etsixe on es oruges on odatse O

aruges aicnqes amu etsixe es oruges odatse O

.oruges odatse o ,kcoldaed rative adnia e ,medro amugla me ,ossecorp adac arap sosrucer racola eugesnoc ametsis o eS

oruges on/oruges odatsE

soirssecen ,opit adac ed ,sosrucer ed omixm o meralced sossecorp so euq matissecen somtirogla sO .kcoldaed rareg mes adidneta res edop oisiuqer a es ridiced eved ametsis o e soirssecen odnauq sodatisiuqer os sosrucer sO

on

kcoldaed

ed

uo

oruges

on

odatse

mu

ametsis

seisiuqer sA .oruges on odatse mu a ametsis o ravel on otnemidneta o es ,oisiuqer adac arap ,odacifirev r of es e ofarg mu odurtsnoc

rof es adanimile oidnoc atsE .olcic omsem ed sossecorp sortuo arap sodacola otse euq sosrucer ed arepse odaeuqolb tse ossecorp adac lauq on olcic mu ed oamrof a levssop rof odnauQ :ralucric arepsE )4

.oanedro atse etiepser euq aicnqes amu me sosrucer so ratisiuqer meved sossecorp so e sodanedro merof sosrucer so es oidnoc atse es-animilE .sossecorp sortuo a sodacola meres arap etnemairaropmet sodacsifnoc res meredup on sosrucer so odnauQ :opmeerp oN )3

6.4 Evitar deadlocks


.sadidneta res oreved o meravel euq

691

2P

1P

0P

edadissecen zirtaM

3P

2P

1P

0P

oacola zirtaM

3P

2P

1P

0P

revirD retnirP

epaT

cor P

.5691 artskjiD olep otsoporp iof e odatse on odaesab )mhtirogla s`reknaB( odatneserpa res euq omtirogla O

skcoldaed rative arap omtiroglA

.ossecorp adac ed amixm adnamed e sodacola ,sievnopsid ed oremn olep odinifed oacola ed odatse O .ralucric arepse amu etsixe on euq rarugessa arap sosrucer ed oacola ed odatse o etnemacimanid animaxe omtirogla O .kcoldaed me rartne acnun ametsis o euq arugessa euq omtirogla mu riurtsnoc levssop ossecorp adac arap soirssecen sosrucer ed omixm oremn ed oamrofni a moC

791

;)(etats_efas

;k - )i,P(deen = )i,P(deen

;k + )i,P(noitacolla = )i,P(noitacolla

;k - )i(elbaliava = )i(elbaliava

{ ))i(elbaliava =< )i,P(tseuqer( fi

{ ))i,P(deen =< )i,P(tseuqer( fi

i osrucer od sedadinu k odnaticilos atse P ossecorp o k = )i,P( tseuqer oisiuqer amu araP

)noitacollA_xaM( ossecorp adac arap sairssecen ,osrucer adac ed ,sedadinu ed oremn o acidni euq zirtaM :deeN

ossecorp adac arap etnemetneserp sadacola ,osrucer ed opit adac ed ,edadinu ed oremn o enifed euq zirtaM :noitacollA

sairssecen ,osrucer ed opit adac ed ,sedadinu ed omixm oremn o ,ossecorp adac arap ,enifed euq zirtaM :xaM

osrucer ed opit adac ed sievnopsid sedadinu ed oremn o acidni euq roteV :elbaliavA

sodad ed aruturtsE

levnopsid rotev

omixm zirta M

3P

891

efas odatse mu me atse ametsis o

neht i odot arap eurt = )i(hsinif fi

;eurt = eunitnoc

;eurt = )i(hsinif

;)i(noitacolla + )i(pmet = )i(pmet

{ )eslaf = )i(hsinif dna )i(pmet =< )i(deen( fi

;eslaf = eunitnoc

{ )eunitnoc(elihw

i odot arap

;eslaf = ]i[hsinif

;]i[elbaliava = ]i[pmet

:sodad ed aruturtsE :etats_efaS

Bibliografia
;eurt = eunitnoc

Exerccios
} } rotev :hsiniF rotev :pmet

;orr e

esle }

991

airmeM/SE/UPC oaretnI 1.8 .giF

oeredne

airmeM

on airmem ed aicnreG .oatnemgeS .oanigaP .gnippawS .sievirav seitraP .saxif seitraP .erawdrah ed sotcepsA e socisb sotiecnoC

7.1 Conceitos Bsicos e aspectos de hardware

. swodniW on e xuniL

7. Gerncia de Memria

rodatupmoc ed sametsis me lartnec

airmem a moc megaretni O/I ed ametsis e UPC

oirprp ues moc mu adac ,sarvalap uo setyb ed )yarra( otnujnoc mu

airmem an otnemanezamra e acsub zaf UPC

odatucexe res arap airmem an odagerrac res eved amargorp mu

002

.acisf airmem a e lautriv airmem a ertne otnemaepam o atneserper oxiab a arugif A .ametsis od ohnepmesed o airazilibaivni euq o ,erawtfos rop atief res eved on oudart a euq acifingis euq o ,soeredne ed oudart amu revah eved osseca odot mE .siautriv soeredne moc atart ossecorp O

oeredne ed oudarT

ossecorp mu ed otnemaeredne ed oapsE 2.8 .giF

.lautriv oapse ues ed etrap reuqlauq rasseca edop ossecorp mu e oatnemges/oanigap adasu es etnemlaicepse ,ocisf oapse o euq roiam res edop lautriv oapse O .)raeredne arap sodasu stib ed .oN( aniuqm ad arutetiuqra alep odatimil lautriv oeredne roiam O .ossecorp mu ed lautriv oapse o .agrexne ossecorp o euq airmem a lautriv airmeM

)sepurretni ed rotev .xe( siaicepse sovitejbo arap erawdrah olep sadavreser os seisop satreC .airmem ad ohnamat o acidni euq ,oeredne roiam o ta aunitnoc e 0 ocisf oeredne on etnemlareg aemoC.erawdrah od airmem a acisf airmeM

lautriv airmeM e acisf airmeM

102

oamargorpitluM

odamargorponom lanoicarepo ametsis mu me airmem ad oazinagrO 4.8 .giF


oirusu od ossecorP

OS

.)riuges a arugif( oirusu

:levssop selpmis siam ameuqse o oamargorponoM

.oucexe me mu e ratucexe sotpa airmem an sossecorp soirv metsixe

oamargorpitlum moC .airmem a adot rasu oditimrep omsem oa e oucexe me airmem an ossecorp ocin mu etsixe ,sodamargorponom sametsis soN

oamargorpitlum e oamargorponoM

acisf airmem a e lautriv airmem a ertne otnemaepaM 3.8 .giF

;airmem an zev rop ossecorp mu

;airmem a adot rasu edop ossecorp o

od ossecorp o e lanoicarepo ametsis o ertne adidivid airmem a

202

.apuco omsem o euq )roirepus e roirefni( airmem ed soeredne so moc sodagerrac os o serodartsiger setse ,oucexe ossecorp o arap e odanoiceles 1P ossecorp amu

odnauQ

.odanimret

,odilvni

oeredne

,oecxe

adareg oirrtnoc osaC .odazilaer osseca o ,ovitisop osac mE .serolav siod setse ertne tse odasseca res a oeredne o es acifirev erawdrah o airmem a osseca odot A .otla siam o ,roirepuS etimiL rodartsiger o e ossecorp etse rop odapuco airmem ed oxiab siam oeredne od rolav o mtnoc roirefnI etimiL serodartsiger o ,oucexe me ajetse 0P euq odnopuS .1P e 0P ,sossecorp siod e lanoicarepo ametsis od oelcn o sodatneserper os amica arugif aN

roirepuS etimiL e roirefnI etimiL serodartsiger ed osU

5.8 .giF

1P roirepuS etimiL 0P roirefnI etimiL oelcN

.roirepus etimil e roirefni etimil serodartsiger ed osu o artsuli riuges a arugif A .etimil e esab serodartsiger ed e ossecorp mu

ed airmem ad roirepus etimil o e roirefni etimil o racidni arap serodartsiger ed oazilitu a erawdrah ed oetorp ed oatnemelpmi a arap sievssop seuloS .ossecorp ortuo ed airmem ed aer a etnemadivedni esseca

on ossecorp mu euq arap )erawdrah( oetorp ed somsinacem soirssecen oS .opmet odanimreted mu rop atucexe mu adac euq odnes ,airmem

an etnemaenatlumis ridiser medop samargorp soirv ,oamargorpitlum moC

302

.etnemroiretna sodatneserpa erawdrah ed somsinacem so moc sadatnemelpmi res medop ,riuges a sadatneserpa ,sieviraV seitraP e saxiF seitraP os airmem ed aicnreg ed sacitlop sauD .etnemaenatlumis airmem an ridiser medop sossecorp sotiu m etimil serodartsiger moC

oeredne ed oudart an etimil e esab serodartsiger ed osU

6.8 .giF

orrE

oN

etimiL rodartsigeR

.etimil e esab serodartsiger ed osu o acifilpmexe riuges a arugif A .ossecorp od otnemaeredne ed oapse od arof oeredne :oecxe amu adareg ,oirrtnoc osaC .)odilv oeredne( odazilaer osseca o ,)etimiL rodartsiger( etimil oeredne od rolav oa laugi uo ronem etnatluser oeredne o eS .esab rodartsiger od rolav oa odanoicida atircse uo arutiel ed oeredne o ,airmem a osseca o d ot A .esab rodartsiger oa odubirta airmem

ed roirefni oeredne o ,odanoiceles ossecorp o odnauQ .searapmoc ed oremn o iunimid siop ,)roirepuS etimiL/roirefnI etimiL serodartsiger( roiretna odotm oa roirepus oulos amu etimil e esab serodartsiger ed osu O

etimil

+
esaB

airmem

<=

miS

oerednE

e esab serodartsigeR

402

.ossecorp od ohnamat o euq roiam oitrap ad ohnamat :anretni

:oatnemgarf ed sopit siod metsixe axif oitrap ed sametsis mE

.setnetsixe seitrap ed oremn olep odanimreted

,aentlumis

oucexe me sossecorp ed omixm oremn o , otsi ,oamargorpitlum ed uarg O .ol-tnoc arap etneicifus ohnamat moc seitrap sad amu me ossecorp o agerrac e sievnopsid reludehcs o otse seitrap arap euq ,airmem mu ed edadissecen ara P

aus

acifirev

,oucexe

amargorp

ragerrac

oxif ahnamat ed seitrap srt me adazinagro acisf airmeM

7.8 .giF

1P

0P

OS

.oxiaba arugif ,)1P( seroiam sossecorp arap K46 ed 1 e )0P( soneuqep sossecorp arap 23 ed a m u r et es-edop amu ,OS o arap K23 ed oitrap

,olpmexe roP .setnerefid sohnamat ed seitrap ed oremn

otrec mu me etnetsixe airmem a ridivid avitanretla artuO .ohnamat omsem o meussop seitrap sa sadot ,osac etseN .K23 ed omsem ed seitrap

4 me adidivid res edop amsem a ,setyBK821 ed airmem amu odnaredisnoC .ametsis mu ed rop od agrac an ,)oirusu repus( siaicepse sad soiglivirp ohnamat od moc O oirusu

odaretla

res

edop

etnemos sa e

seitrap

.oacilpa olep

samargorp

solep

siamed

,lanoicarepo

ametsis

ogidc

adapuco seitrap sad amU .oxif ahnamat ed seitrap ed oremn otrec mu me airmem a edivid lanoicarepo ametsis o saxiF seitraP ed osu o moC

7.2 Parties Fixas e Parties Variveis

502

.levnopsid K 821 ed ocin ocolb mu moc ,sievirav seitrap ed osu o moc adazinagro airmem amu artsuli riuges a arugif A .levnopsid otnujnoc oa adaroprocnier euq ,airmem aus arebil animret ossecorp mu odnauQ .ol-tnoc arap etneicifus ohnamat moc ocolb mu odasiuqsep airme m atissecen e agehc ossecorp mu

odnauQ .ocin ocolb mu omoc adaredisnoc ,levnopsid atse airmem a adot etnemlaicinI .sadapuco otse siauq e sievnopsid otse airmem ad setrap euq odnacidni alebat amu mtnam lanoicarepo ametsis O :sievirav seitraP

.)aizav alif( sievnopsid ratse medop airmem ed seitrap )s(artuo otnauqne oitrap amu

me oucexe arap sodagerrac res odnarepse sossecorp soirv moc alif amu ret es-edop ,osac etseN .sossecorp ed alif airprp aus met oitrap adaC )b

.sednarg seitrap me sodagerrac res medop soneuqep ed sossecorp revah euq adidem euq an ,oitrap a anretni

.adinifedni oagretsop a ravel edop oulos ats E .)alif amu res ed axied

euq( alif an ossecorp ortuo mu ranoiceles ridiced edop rodanolacse o ,osac etse N .oitrap ad ohnamat o euq od roiam airmem ed

:os rerroco medop euq samelborp ,setnerefid os seitrap sad sohnamat so e airmem ed sedadissecen

sa omoC .oucexe arap anoiceles so rodanolacse o edno ed ,rador a sotpa aossecorp ed alif acn amu me sol-coloc e )ametsis olep uo oirusu olep adacificepse( airmem ed sedadissecen saus moc odroca ed sol-cifissalC )a

:os airmem ed oacola arap savitanretla ,oucexe arap soditembus os sossecorp so odnauq ,saxif seitrap mazilitu euq sametsis mE

.odatucexe res arap odnarepse ossecorp od ohnamat o euq ronem adasu on oitrap :anretxe

atissecen alif ad ossecorp oriemirp o e levnopsid anrot es oitrap amu

oatnemgarf

otnemua

edop

amelborp

ortuo

mU

602

sodapuco sohnamat setnerefid ed socolb moc sievirav seitraP 9

.8 .giF

K08

tlU

K8 K82 K21

mirP

.oxiaba arugif an odartsom airmem ed oacola ed apam o ,K8 ed atissecen 2P ossecorp mu euq e K82 ed atissecen 1P ossecorp mu euq ,K21 ed

atissecen euq e oucexe arap oditembus iof 0P ossecorp mu euq odnopuS

levnopsid ocolb ocin mu moc sievirav seitraP

8.8 .giF

tlU

K 821

mirP

702

.ocolb ocin mu odnamrof

;servil socolb ed otnujnoc

;servil socolb so arap anroter ortuo o e ossecorp o arap odacola

:sievirav seitrap ed acitlop ad sacitsretcaraC

sodapuco e servil sohnamat setnerefid ed socolb moc sievirav seitraP 01

.8 .giF

K08

tlU

K8 K82 K21

mirP

:oxiaba arugif an odartsom etnatluser airmem ed apam O .omitl o euq ,K8 ed ocolb mu arap atnopa euq ,K21 ed ocolb mu arap atnopa euq ,oriemirp o euq ,K08 ed ocolb mu rop atsopmoc acif sievnopsid socolb ed atsil a ,maiussop euq airmem a merebil e menimret 2P e 0P sossecorp so euq odnopuS

;sohnamat setnerefid ed servil socolb metsixe

mu ,siod me odidivid ,ossecorp mu arap ednarg otium ocolb mu es

on adacoloc atse odnes ,airmem a arebil animret ossecorp mu odnauq

sodapurga res medop ,ervil ortuo etnecajda odarebil ocolb o es

802

.saxif

seitrap ed

son euq od sievirav seitrap ed sametsis son rohlem etnemlareg airmem ed oazilitu a ,adniA .serodartsiger son airmem ed soeredne so agerrac rehctapsid o ,odanoiceles ossecorp mu odnauq ,sacitlop satse araP .artuo

uo amu ed osu o ranimreted ri euq erawtfos O .sacitlop sad amu reuqlauq ed oatnemelpmi serodartsiger( seitrap a etimrep )etimil/esab erawdrah ed serodartsiger o ,roirepus/roirefni sadatneserpa

etimil

oirssecen e s a x if

,etnemroiretna sa

,sievirav

seitrap

sacitlop

es-odnaredisnoC

.roiam ohnamat ed ,ocolb ocin mu me setnecajda soeredne ed e sievnopsid sairmem ed socolb so rinu a me etsisnoc euq ,oatcapmoc a adazilitu oulos amU .oatnemgarf sievirav seitrap ed sametsis son etnatropmi amelborp mU

.etnemroiretna odatic amelborp olep ,tif-tseb a roip A .tif-tsrif a sodatluser serohlem atneserpa euq e airmem ed oacola arap adazilitu siam oulos A

.sednarg sotnemgarf rareg aidi a ,acinct atse

.soneuqep airmem ed sotnemgarf ed oareg a aicndnet amu etsixe euq oulos atsed amelborp O .odatisiuqer

.oisiuqer an adaticilos airmem ed ohnamat o e lanigiro ocolb od ohnamat od anerefid a ohnamat ojuc ,sievnopsid socolb ed atsil a odatnecserca res eved euq ocolb odnuges mu e odaticilos ohnamat o mtnoc euq e etnatisiuqer oa odanroter oeredne ojuc oriemirp o :siod me odidivid odacola ocolb O .oisiuqer a redneta arap etneicifus ohnamat

:sossecorp so arap airmem ed oacola arap savitanretla srt metsixe ,levirav oitrap ed sametsis mE

moc sievnopsid socolb ed atsil ad ocolb oriemirp o racola :tif-tsrif

od omixrp siam ohnamat o moc airmem ed ocolb o racola :tif-tseb

moC .etnetsixe levnopsid airmem ed ocolb roiam o racola :tif-tsrow

902

acifirev ,revitse on eS .airmem an tse odanoiceles ossecorp o es acifirev euq tceles o amahc ossecorp mu ratucexe ediced gniludehcs o odnauQ

.oamargorpitlum ed uarg otla mu odnitimrep ,sossecorp ed oremn ednarg mu ranezamra redop a arienam ed adicelebatse

res eveD .lanoicarepo ametsis od otnemicehnoc ed e ocsid od oatamrof a etnarud adacola ,adinifed oazilacol amu apuco pawS ed aer A

.paws ed aer an e lapicnirp airmem an sossecorp rop adamrof tsil ydaer a ,amrof atseD .airssecen airmem a rarebil

arap pawS ed aer a arap odavel res reved ortuo mu ,oirssecen eS .)ni pawS( lapicnirp airmem an odagerrac res eved oucexe arap odanoiceles pawS ed aer an ossecorp mu odnauQ .tsil ydaer an odizudortni

e airmem a arap odagerrac ossecorp ovon o e oautis atse rotircsed ortsiger euq ues on od odalanissa soeredne ,)tuo pawS( pawS ed aer a mednopserroc odaipoc

ocsid

so

arap

lapicnirp

airmem

ad

,pawS ed aer a arap odavel res arap odihlocse ossecorp mu ,ritsixe on ed osac oN .levnopsid airmem a acifirev ametsis o oucexe arap oditembus ossecorp mu odnauq :etniuges o acitlop atsed otnemanoicnuf O

.pawS ed aer an otse euq solep e lapicnirp airmem an otse euq sossecorp solep odamrof aentlumis oucexe me sossecorp ed oremn o , a m r of atseD .oucexe arap sossecorp sortuo ed agrac

a amrof atsed odnatilibissop ,airmem rarebil arap ocsid arap res medop oucexe me sossecorp so ,acitlop atse moC

sodirefsnart :gnippawS

.oatnemges e oanigaP ,gnippawS os ,oucexe ed opmet me ,ocsid o e airmem a ertne sossecorp matnemivom euq sacitloP .ossecorp ortuo mu a adacola res arap adarebil airmem atse euq onimrt ues oa etnemos e ,airmem ed

augtnoc aer amu me oucexe arap sodagerrac os sossecorp so ,sievirav seitrap e s a x if seitrap ,etnemroiretna sadatneserpa sacitlop soN

7.3 Swapping, Paginao e Segmentao

012

.airmem ed ocisf oeredne o

:setrap saud mtnoc UPC alep odareg oeredne O

ocisf oeredne o arap ocigl oeredne od oamrofsnarT

.etnednopserroc ocisf oeredne on ocigl oeredne od oamrofsnart amu atief airmem osseca adac a e ocigl ourtsni an oditnoc oeredne O .soeredne setse retnoc a arienam ed ,adazilauta

sanigp ed alebat aus a e ,sadacola acisf airmem ed sanigp sa arap odagerrac ossecorp o ,riuges A .ossecorp o arap acola ,odnitsixe ,etneicifus oremn mu etsixe es sievnopsid semarf ed atsil an acifirev ,asicerp el euq sanigp ed oremn o acifirev gniludehcs o ,oucexe arap odagerrac res eved ossecorp mu odnauq :etniuges o acitlop atsed otnemanoicnuf O

.setybK4 ,setybK2 ,setybK1 res medop socitsretcarac sohnamaT .erawdrah olep odinifed me anigp ad ohnamat saus O .lapicnirp airmem res an sievnopsid amargorp

semarf

sadagerrac

segap

met

odatucexe

arap

mU .ohnamat laugi ed ,segap me adivid acigl airmem a e semarf me adidivid acisf airmem a ,airmem ed aicnreg ed acitlop atsed osu o moC

oanigaP

.iunimid aicnrefsnart ed euq o p m et etse A ,ovitisopsid .adirefsnart opmet o sod res aicnrefsnart a airmem ad ed edadicolev oa a atnemua

adidem ,paws

ohnamat mu

lanoicroporp atseN

euq

ed

etnatropmi

otcepsa

,acitlop

.odanoiceles ossecorp o arap elortnoc o erefsnart e serodartsiger so a r u a t s er ,airmem an ajetse euq ossecorp ortuo mu anoiceles

,riuges A .odanoiceles ossecorp od ni paws e airmem ad rias arap odihlocse ossecorp mu ed tuo paws arapsid ,oirrtnoc osa C .odanoiceles ossecorp

od ni paws arapsid ,revuoh eS .ol-domoca arap levnopsid airmem etsixe es

;sanigp ed alebat amu aeredne - )p( :anigp ad .oN

enifed anigp ad esab oeredne o moc odanibmoc - )d( :otnemacolsed

112

:setniuges so os sossap so i oeredne rasseca araP .amelborp o airmem ed oisop amu a osseca ed opmet o ,b oulos a araP .aneuqep sanigp ed alebat a es adatoda res ed levssop etnemos oulos ariemirp A

.)odetnoc olep leveredne airmem( avitaicossa airmem ed osu

)c

;sanigp ed alebat

lapicnirp airmem an

:serodartsiger ed otnujnoc mu ed osu

:os sanigp ed alebat ad oatnemelpmi a arap savitanretlA

oanigap moc oeredne ed oudarT 11

.8 .giF

f
ocisF oerednE

acisf oazilacol

D +

f
sanigp ed alebaT

D acisf airmeM

ocigl oerednE

.adasseca res a airmem ed oisop a acidni ,anigp ad esab oeredne o moc odanibmoc ,otnemacolsed O .anigp ad esab oeredne o mtnoc euq ,sanigp ed alebat amu raxedni arap adasu anigp ad oacifitnedi a mtnoc euq oeredne od etrap a ,)riuges a arugif( ocisf oeredne me ocigl oeredne ed oamrofsnart a araP

;ortuo reuqlauq omoc sodagerracer

.siaicepse seurtsni rop sodacifidom/sodagerrac

)b )a

a arap atnopa )rbtp(-retsiger esab elbat egap- rodartsiger mu

212

.otxet ed serotide e serodalipmoc os ogidc mahlitrapmoc euq samargorp ed solpmexE .lapicnirp airmem ed )sanigp samsem

sa arap matnopa( soeredne somsem so meussop ogidc o mahlitrapmoc euq sossecorp sod sanigp ed salebat sa ,acinct atse moC .sovitavirp

os sodad so euq odnes ,sossecorp sosrevid ertne odahlitrapmoc res edop ogidc O .otnemanezamra ed oapse azimito etnemetneqesnoc e airmem ed otnemahlitrapmoc etimrep siop etnatropmi etnemralucitrap acinct amu

sanigP ed otnemahlitrapmoC

aicnrefer amixrp an etnemadipar odartnocne res a odom ed ,avitaicossa airmem an sodacoloc os e m a rf ad oremn o e anigp ad oremn

o ,osac etseN .airmem a rasseca arap odasu euq emarf ad oremn o retbo arap ,lapicnirp airmem an ,sanigp ed alebat a osseca mu otief ,odartnocne on anigp ad oremn o eS o .airmem a rasseca anigp arap ad etnemataidemi oremn o eS

odasu

emarf

ad

oremn

,odartnocne

.)avitaicossa airmem an( emarf ed oremn/anigp ed oremn mtnoc lauq a ,etnemaenatlumis sanigp ed alebat ad sadartne sa sadot moc odarapmoc UPC alep odareg ocigl oeredne mU .sanigp ed alebat ad sadartne sacuop mtnoc ,missA .saneuqep os etnemlamron ,sotsuc sues soa odived ,mrop ,lanoicidart airmem a euq adipr siam airmem amu ed es-atarT .airmem a osseca ed sopmet so azimito avitaicossa airmem ed ooda A

.adajesed arvalap a retbo arap airmem a sosseca siod soirssecen os ,otnatroP

.)osseca .o2( acisf airmem an i oisop a rasseca

.3

;i o

dne o zudorp euq e otnemacolsed .2

moc odanibmoc res eved euq emarf ed .oN mu zudorp 1 ossap o

;)airmem osseca .o1( ).colsed egap.oN +rbtp od osu( sanigp ed alebat rasseca .1

312

.sotnemges ed alebat

;ossecorp od sotnemges ed alebat ad esab

:serodartsiger siod es-azilitu ,edadilibissop adnuges a ara P .aneuqep sotnemges ed

alebat a es leviv etnemos ,oanigap ed olpmexe a ,avitanretla ariemirp A

.sadasu etnemetnecer siam sotnemges ed alebat ad sadartne sa retnam arap avitaicossa airmem ed osu )c

;airmem an sotnemges ed alebat )b

;serodartsiger ed otnujnoc )a

:rop atief res edop sotnemges ed alebat ad oatnemelpmi A

sotnemgeS ed alebat ad oatnemelpmI

.airmem ed acisf oisop a acidni esab oeredne o moc odanibmoc euq ,otnemacolsed o artuo a e otnemges od esab oeredne o mtnoc euq ,sotnemges ed alebat amu raxedni arap adasu amu :setrap saud rop odamrof ocigl oeredne mu ,oatnemges ed osu o moC

.otnemges od oicni oa oaler me ,otnemacolsed olep e otnemges od emon olep odacificepse oeredne O

.ohnamat mu e emon mu met otnemges adac euq odnes ,osiv atse atropus euq airmem ed aicnreg ed ameuqse mu oatnemgeS .levirav ohnamat ed otnemges mu mu adaC .emon olep sodirefer os euq ).cte ,salebat(

sodad ed saruturtse ,senuf ,sanitorbus ed otnujnoc mu amargorp mU

oatnemgeS

oeredne o arap atnopa :)retsiger esab elbat tnemges( RBTS

ad ohnamat o mtnoc :)retsiger htgnel elbat tnemges( RLTS

412

.soxelpmoc siam otnatrop odnes ,levirav euq ,otnemges od ohnamat od ratart mairatissecen ,oatnemges moc sodazilitu meres somtirogla so araP .oanigp

a merefer es riuges a sodatneserpa somtirogla e sotiecnoc sO .oatnemges e oanigap ed somsinacem so es-odnasu atief res edop lautriv

airmem ed oatnemelpmi A .airmem e ocsid ertne aicnrefsnart ad atart euq OS o siop ,etnerapsnart oirusu o arap otsI .ocsid me otse setrap e airmem an otse amargorp od setrap ,laer airmem a euq roiam res edop ossecorp od lautriv airmem a omoC .erawdrah od oilxua o moc ,lanoicarepo ametsis a arap olep )ocigl( atief )ocisf od oeredne( oudart A a c i s f .socigl airmem os an oazilacol so lauq

oeredne

soeredne

an ,lautriv airmem amu iussop oucexe me amargorp O .acisf oazilacol ed otnitsid amargorp on etnetsixe oeredne o euq ed aidi atsen lapicnirp otcepsa O .etnetsixe a euq od roiam ,ednarg otium lapicnirp airmem amu iussop ele euq ed osuli a rodamargorp oa rad lautriv airmem moc aidi A

oeredne mu me ocigl oeredne mu ed oamrofsnart a arap ,oanigap an omoc ,sosseca siod reuqer airmem an sotnemges ed alebat A

ad atief ocisf oeredne mu me )d,s( ocigl oeredne mu ed oamrofsnart A

7.4 Memria Virtual


.ocisf .orr e ones ;d + S = oeredne ;RBTS + s = S otne ) RLTS < s( eS :arienam etniuges

512

ossecorp o e oautis atse racidni arap odaretla airmem an anigp ad aneserp ed tib o ,aicnrefsnart atse spA .lapicnirp airmem an ragul redec arap adihlocse anigp a erbos adavarg res redop anigp avon a ,oirrtnoc osa C .ocsid me adavarg res reved amse m a ,oaretla odirfos revit

adivomer res euq anigp a eS .airssecen anigp ragul rad arap ,airmem ad adivomer res reved euq ,anigp amu ranoiceles reved lanoicarepo

ametsis O a c if anigp

.airmem a arap adirefsnart ajes anigp a euq arepse a odaeuqolb ed atlaf a uoreg euq ossecorp o ,opurretni amu adareg

,ocsid on tse anigp a eS .atelpmoc es oudart o ,airmem an tse anigp a eS .on uo acisf airmem an rartnocne es edop adaicnerefer anigp a ,atief ocisf oeredne o arap ocigl oeredne od oudart a odnauQ

.airmem a osseca adac a sodazilauta os adacifidom e adaicnrefer anigp ed stib sO

sanigp ed alebat an adartne amu ed aruturtsE 21


etnesua/etneserP aicnrefeR

.8 .giF

ehcac

anigp ad oremN

oetorP

oacifidoM

.)oxiaba arugif( .arutiel ed etnemos uo atircse res edop anigp a es acidni euq ,oetorp ed tib mu e lapicnirp airmem an aneserp ed ed tib o ,adacifidom airmem anigp acidni euq ortuo ,adaicnerefer a es acidni

anigp

mu

,ehcac

an

etneserp

tse

anigp

euq mu :stib ocnic sodaicossa os ossecorp od

anigp adac A

.airmem a

arap ocsid od adirefsnart res anigp airssecen odnauq etnemoS .airmem an ajetse ,amargorp od laicini ogidc o mtnoc euq a ,anigp amu etnemos euq atissecen odatucexe res arap amargorp o ,oanigap moC

612

sanigp ed oiutitsbus ed somtiroglA 1.4.7

.adutitsbus res arap lapicnirp airmem ad anigp amu ranoiceles reved lanoicarepo ametsis o ,osac etseN .airmem an etneserp tse on anigp atse ,2 anigp a erefer es 0P rop odaicnerefer oeredne o eS

.4 e 2 sanigp sa lapicnirp airmem an iussop 1P ossecorp O .)odilvni i aneserp ed tib( setneserp on 4 e 3 ,2 sanigp sa e )sanigp ed alebat an v( lapicnirp airmem an setneserp 1 e 0 sanigp sa iussop 0P ossecorp o euq artsom amica arugif A

sanigp ed salebaT ed solpmexE 21

.8 .giF
b j a h 3 2 1 0

lapicnirp airmeM

v i v i i

4 3

J I H G F

4 3 2 1 0

2 1 0

1P ed anigp ed alebaT

1P

i I I V V 3 1

4 3 2 1 0

E D C B A

4 3 2 1 0

0P ed sanigp ed alebaT

0P

:oautis etniuges a ret someredop ,sanigp ortauq rop adamrof lapicnirp airmem amu e sacigl sanigp ocnic moc mu adac ,1P e 0P , sossecorp siod odnaredisnoc olpmexe roP .rador a sotpa sossecorp ed atsil an odiresni

712

ecnahC adnugeS ad omtroglA

.odazilitu etnemarar omtrogla etsE .adaicnerefer odnes ajetse adihlocse anigp a euq lat arap odnatsab ,ametsis od ecnamrofrep an etnemavitagen rirefretni avon res A a l if redop .on ad uo ahlocse adazilitu atsE odnes a .alif ad es lanif on adacoloc res anigp

tse

etnemetnednepedni ed a atlaf moc amu odroca

,adutitsbus odnauQ sa

anigp

ariemirp

,sanigp ed medro

rerroco ed

.lapicnirp

airmem

an

adagehc

sanigp

odnetnoc alif amu airssecen omtirogla etse ratnemelpmi araP .opmet siam h airmem an tse euq a adutitsbus res a anigp a ,omtirogla etse moC

)rias a ariemirp a lapicnirp airmem an rartne a anigp ariemirp( OFIF omtiroglA

.airssecen etnemavon res anigp amu odnauq rebas lanoicarepo ametsis o omoc met on siop ,levtnemelpmi on omit omtirogla O .amargorp od ogidc on setnetsixe sesiced sad e sodad sod odnedneped ,riteper es on redop aicnuqes a sam ,aicnrefer ed gnirts o retbo e amargorp o ratucexe es-edop ,oamrofni atse retbo

es araP .sanigp ed atlaf amu ed aicnrroco a arap opmet o odnatnemua es airatse ,ossi moC .ouqngnol siam opmet on airssecen res euq anigp a oiutitsbus arap ranoiceles arap ,orutuf )aicnrefer ed aicnuqes( aicnrefer

ed gnirts o aehnoc es euq atissecen omit omtirogla o ,sanigp ed atlaf ed oremn od oaziminim a omit omtirogla ed oirtirc omoc odnaredisnoC

omit omtiroglA

.airmem an setnetsixe sanigp ed otelpmoc otnujnoc o odnaredisnoc atief ahlocse a odnauq labolg .sanigp ed atlaf a uoreg euq ossecorp oa mecnetrep euq sanigp sa ertne ahlocse a odnauq lacol .labolg uo lacol res edop ,)amitv anigp( adutitsbus res a anigp ad ahlocse ed acitlop A .sanigp ed atlaf rop sepurretni sa res a anigp ad ahlocse a raziminim reved euq o arap ,adutitsbus amelborp O

lanoicarepo

ametsis

812

:arienam

etniuges ad anoicnuf omtirogla o ,otnatroP

.adailava otne euq anigp amixrp a arap anava sanigp ed rodatnopa o e 0 rolav o ebecer ,1 rolav o iussop R tib o eS .etniuges anigp a arap ratnop a assap rodatnopa o e adagerrac res atissecen euq anigp ragul odnedec ,airmem ad ias anigp a ,orez R tib o eS .adailava )alif ad aebac( adatnopa anigp a ,anigp ed atlaf amu erroco odnauQ .oigler mu omoc atsiv res edop euq ,ralucric alif amu ed etrap mezaf airmem an sanigp sA

oigleR od omtiroglA

.odaredisnoc opmet ed olavretni on adaicnerefer odis ahnet on euq e etnetsixe essalc ronem ed anigp amu etnemairotaela adihlocse reS

adacifidom ,adaicnerefeR adacifidom on ,adaicnerefeR adacifidom ,adaicnerefer oN adacifidom on ,adaicnerefer oN odacifingiS

1 0 1 0 M tiB

1 1 0 0 R tiB

3 2 1 0 essalC

:oxiaba sessalc sa odnaredisnoC .adutitsbus res reved euq anigp ad ahlocse a arap M e R stib so aredisnoc omtirogla etsE

)RUN( etnemetneceR adasU oN anigp ad oiutitsbus ed omtroglA

.OFIF me amrofsnart es omtirogla o e 1 rolav o moc R tib o mt alif ad sanigp sa sadot ,osac roip oN .alif ad ariemirp a aroga euq anigp ad R tib o etnemavon ranimaxe a aemocer omtirogla O .ecnahc adnuges amu odnebecer ,alif ad lanif o arap iav anigp a e ,odarez ,odaredisnoc opmet ed olavretni omitl on adasseca iof anigp a euq odnacidni 1 rolav o iussop R tib o eS .adutitsbus res a atadidnac ,alif ad ariemirp a ,airmem an

ahlev siam anigp A .R tib o moc OFIF od oanibmoc amu omtrogla etsE

912

00993876099911148871130997766266000559992142376423

,oxiaba arugif a odnaredisnoc ,olpmexe roP

.t o p m et e d olavretni omitl on sadaicnerefer etnemetnecer siam sanigp sad otnujnoc o ossecorp mu ed )tes gnikrow( ohlabart ed otnujnoc O .oucexe aus ed esaf adanimreted amu me sanigp ed otnujnoc mu etnemos aicnerefer ossecorp mu euq aredisnoc euq otiecnoc mu aicnrefer ed edadilacoL .sanigp ed atlaf sasse atart euq omtirogla od oucexe a odnanigiro ,sairssecen os airmem an setneserp on sanigp ,anava oucexe a euq adidem anigp a etnemos

A .airssecen oucexe ed oicni ed otnop o mtnoc euq

amargorp ovon mu ed oucexe a raicini arap ,lautriv airmem ed osu o moC

)teS gnikroW( ohlabart ed otnujnoc ed otiecnoc O

.anigp ad oazilitu a acidni odateser iof tib o euq sezev ed oremn od rodatnoc mU .sodarez os R stib so ,)opurretni adac a olpmexe rop( opmet ed seraluger solavretniA .R tib o odaredisnoc res edop ,omtirogla etse ratnemelpmi araP .adasseca res mes opmet siam a tse euq anigp a , otsi ,atsil ad lanif on anigp a adiutitsbus reS .adazilauta atsil atse airmem a osseca o odot mE .atsil ad lanif on sadazilitu sonem sa e ,etnerf an sadasu siam sanigp sa odnetnoc atsil amu mtnaM .sadasu res a etnemavon oratlov etnemetnecer sadasu sanigp sa euq ed oipcnirp od etrap omtirogla etsE

)URL( adasu etnemetnecer soneM anigp ad oiutitsbus ed omtiroglA

.orietnop o anava e 0 = R zaf 1 = R eS

orietnop o anava e anigp a ariter otne 0 = R eS

022

airme m

an

odaepam

on

oeredne

mu

rasseca

atissecen

oucexe

me

amargorp o odnauQ .ocsid me acif amargorp od etnatser O a merefer es airmem a arap sodaipoc marof euq

.acisf airmem amargorp

levtucexe

od etrap ad soeredne so euq racidni arap sadatsuja os sodad ed saruturtse sA .airmem a arap iav etrap amu e otreba levtucexe ogidc o odnetnoc

oviuqra o ,oucexe arap amargorp mu etembus oirusu o odnauQ .adnamed rop oanigap odnazilitu airmem aicnereg xuniL lanoicarepo ametsis O

.oomer a atadidnac e opmet ed olavretni omitl o etnarud adaicnerefer iof on anigp a ,0 aicnrefer ed tib o eS .adivomer res eved on e tes gnikrow oa ecnetrep atse ,1 rolav o iussop anigp ad aicnrefer ed tib o es ,sanigp ed atlaf amu erroco odnauQ .)opurretni( opmet ed olavretni adac a odarez e adaicnerefer anigp a odnauq 1 me odacoloc tib O .airmem a saicnrefer ed oremn o res edop tes gnikrow od ohnamat o , otsi ,alenaj A .anigp ad aicnrefer ed tib od oazilitu a moc adagerpme res edop euq amrof amU

.adutitsbus res arap tes gnikrow oa ecnetrep on euq anigp amu adartnocne res eved erroco anigp ed atlaf amu odnauQ .alenaj a setnecnetrep , otsi ,tes gnikrow oa setnecnetrep sanigp sa airmem an recnamrep oreveD .alenaj ad ohnamat o ranimreted sanigp ed saicnrefsnart sa raziminim arap tes gnikrow od oazilitu ad amelborp O .t o p m et o n ossecorp olep sadaicnerefer sanigp ed otnujnoc o ,)r ,t(W t opmet on tes gnikrow O .Kr aicnrefer ed gnirts on h ohnamat ed alenaj amu ed odetnoc o ,)h ,k(W amargorp mu ed tes gnikrow o ,sarvalap sartuo mE .sadasseca res ed maraxied siop otse on
2SW 1S W ,2SW

o e }76432{ sanigp salep odamrof

7.5 Gerncia de Memria no Linux e no Windows


on setneserp siam od ,4 e 3,2 sanigp sa euq evresbO
)1SW (

.}0976{ sanigp salep

tes gnikrow oriemirp O

2S W

1S W

122

.etnaticilos ossecorp oa odanroter otne odacola ocolb O .ohnamat ues oa etnednopserroc atsil an odiresni e levnopsid omoc oditnam etnatser o e odidep o redneta a arienam ed odidivid ,odaticilos o euq od roiam odacola ocolb o eS .ocolb mu racola ta ,etnaid rop missa e ,odaticilos ohnamat od orbod o iussop euq ocolb mu otne racola arucorp ,artnocne on eS .odidep ohnamat o moc o ,atief oisiuqer amu odnauQ sanigp ed ocolb mu rop arucorp omtirogla .ocolb ed ohnamat adac arap sievnsopdid

socolb ed atsil amu etsixe e )... ,sanigp 4 ,sanigp 2 ,anigp 1 ed ohnamat meussop socolb so( 2 ed aicntop amu euq ohnamat mu meussop sanigp ed socolb sO .sanigp siam uo amu moc ocolb mu racola atnet omtirogla e tsE .yddu B omtirogla o asu xuniL o ,sanigp ed oacola ara P

.etnerapsnart res reved oudart atse lenrek o araP .sanigp ed alebat ed sievn srt so ertne oudart ed somsinacem revorp eved samrofatalp setnerefid san xuniL od oatnemelpmi A o .ocisf moc oeredne o acidni ,ourtsni ed ad etrap ad zaf euq otnemacolsed o mtnoc

odanibmoc

,euq

airmem

anigp

esab

oeredne

euq ,srt levn ed sanigp ed alebat ad otnemacolsed o mtnoc euq ,2 levn ed sanigp ed alebat ad otnemacolsed o mtnoc1 levn ed sanigp ed alebat an adartne amU .sievn srt iussop sanigp ed alebat a ,xuniL o araP

.gnippaws arap satadidnac saob os )etnemetnecer sonem sadasseca( sahlev siam sanigp sA . a n r ot es anigp amu a mevoj siam ,adasseca anigp adoT a siam otnauQ res

.adaicossa

edadi

iussop ametsis on anigp a

.adutitsbus

a anigp ad ahlocse arap )adasU etnemetneceR soneM( URL omtirogla o asu xuniL O .paws ed oviuqra on evercse a xuniL o ,adaretla iof anigp a eS .ocsid me ossecorp od megami ad adagerrac res redop ,airssecen rof odnauQ .lautriv anigp a ranezamra arap adazilitu res etnemselpmis edop ,adaretla iof on amitv omoc adihlocse anigp a eS .airssecen anigp a radomoca arap oapse mu rairc atissecen xuniL o ,levnopsid airmem etsixe on e )ocsid me tse e u q( lautriv anigp amu ed atissecen ossecorp o odnauQ

.odazilaer res otne edop osseca o e airmem arap ocsid od anigp a erefsnart xuniL o ,acisf

222

.sossecorp sod oucexe ed opmet o riunimid odnavitejbo ,sanigp ed atlaf ed oremn o raziminim atnet ,ossi moC .roder oa samugla e avatlaf euq anigp a agerrac airmem ed rodaicnereg o ,anigp ed atlaf amu erroco odnauQ .gniretsulc moc adnamed rop oanigap azilitu TN swodniW O

.odasseca res a ocisf oeredne o acidni otnemacolsed oa odamos ,euq adasseca res a anigp ad esab oeredne o iussop sanigp ed alebat ad adartne adaC .lautriv oeredne oa etnednopserroc sanigp ed alebat ad adartne a ranimreted arap odasu sanigp ed oeredne O .anigp ad ortned otnemacolsed e sanigp ed salebat ed ecidn ,sanigp ed oirterid ed ecidn :setnenopmoc srt rop odamrof stib 23 ed lautriv oeredne mU .sievn siod me oanigap ed alebat amu adasu ocisf oeredne mu me lautriv oeredne mu ed oudart a araP

.ossecorp o arap sadaepam j

:sadacided ;ocisf :sadavreser

ocsid me sadaepam on mrop ,ossecorp mugla a sadacola

;ossecorp olep sadazilitu on :ervil :sodatse srt meussop sanigp sA .sadazilitu os sadavreser mavatse j euq sanigp satse ,sanigp ed atissecen ossecorp o odnauQ .odavreser lautriv airmem ed sanigp ed oremn otrec mu ,odagerrac ossecorp mu odnauQ .lanoicarepo ametsis o arap setnatser BG2 so odnacif ,BG 2 odubirta etnemlamron oirusu od ossecorp

oA .lautriv airmem ed BG 4 raeredne etimrep euq o ,stib 23 ed raenil oapse mu aredisnoc airmem ed aicnreg ed omsinacem o TN swodniW oN

.etnednopserroc atsil an ,roiam ohnamat ed ocolb o moc aroga eteper es ossecorp etsE .roiam ohnamat ed ocolb ocin mu ramrof a arienam ed sodanibmoc os odnitsixE .setnecajda soeredne moc ohnamat omsem ed ocolb mu etsixe es acifirev a omtirogla ed ed o ,odarebil ocolb mu odnauQ sodarebil .airmem A

.seroiam socolb ed

socolb

ramrof

arienam sanigp edop

,sievnopsid oarebil ed ed

socolb

moc O

so

ranibmoc a

a t n et ravel

omtirogla ed

oatnemgarf

sanigp

socolb

oacola

322

.atsopser aus euqifitsuJ ?aterroc tse

airmem an sossecorp siam

ahnet es ,seitrap ed odavele oremn mu es-odninifed ,euq metimrep e etnetsixe airmem ed oapse o rohlem matievorpa siop ,sievirav seitrap euq setneicife siam os saxif seitraP
oamrifa A .6

.ervil oitrap amu me amargorp mu agrac a avercsed e airssecen sodad ed )s(aruturtse )s(a anifed ,otnemacolsed e esab serodartsiger metsixe euq e ,seitrap sa ertne sedadiroirp

metsixe on euq odnebaS .amu adac oxif ohnamat ed seitrap zed me adaicnereg BM2 ed airmem amu euq me ametsis mu eredisnoC .oazilitu aus ed olpmexe mu etneserpa e ,sanigp ed otnemahlitrapmoc ed osu o euqifitsuJ .4 .5

.saxif seitrap moc airmem ed aicnreg ed sametsis me sossecorp ed otnemanolacse o atucsiD .gnippawS e sievirav seitraP ,saxiF seitraP erapmoC .sodapurga res meved somsem so ,ortuo mu a etnecajda rof odarebil res a ocolb o es euq odnebas ,)rdda(eerf otnemidecorp o mbmat avercs E .)etneicifus ohnamat moc ocolb .3 .2

oriemirp o( tiF-tsriF adazilitu res a oacola ed acinct A .odacola ocolb od esab oeredne o ,adamahc ad onroter on ,mtnoc rdda

e odacola res eved euq ocolb od ohnamat o n edno ,)n( memcolla = rdda otnemidecorp o avercsE .omitl o arap ortuo e ,atsil ad otnemele o o arap arap mu ,serodatnopa mu e siod ocolb metsixE adac ed .atsil ad otnemele o ,ocolb

oriemirp omixrp

rodatnopa

ohnamat

od esab oeredne o odnetnoc sodad ed aruturtse amu rop adinifed atsil assE .sohnamat setnerefid ed ,sievnopsid socolb ed adaedacne atsil amu rop adaicnereg e airmem a euq me ametsis mu eredisnoC .1

.ossecorp od ohnamat od onuf me sodinifed os euq setse serolav ,airmem an setneserp sanigp ed omixm e ominm oremn mu inifed ametsis O .ossecorp od tes gnikrow o adnia odaredisnoc otcepsa ortuO .OFIF o omtirogla o ,sarodassecorpitlum

saniuqm araP .)kcolc( oigler od omtirogla od svarta odatnemelpmi ,URL o TN swodniW on adazilitu sanigp ed oiutitsbus ed omtirogla O

Exerccios

422

.oanigap e saxif seitrap erapmoC .oucexe me sossecorp sod A mu ed onimrt so o odnaredisnoc socolb siod arugif avon amu aaf ,riuges ed atsil

.)sohnamat

anifed(

odnetnoc

sievnopsid

a e BM6 e BM8 ,BM21 ,etnemavitcepser ,moc ,airmem an sossecorp srt odnatneserper arugif amu aaF .sievirav seitrap ed osu o moc adaicnereg BM46 ed airmem amu euq me ametsis mu eredisnoC .7

Bibliografia
.8

522

:os sotnemidecorp siapicnirp sO .soviuqra ed oalupinam a etimrep euq ,acetoilbib ed sotnemidecorp O

ed amrof a bos ,ecafretni amu oirusu oa ecerefo lanoicarepo ametsis

seraluger soviuqra soa ossecA

.socirfirep son odanezamra tse oviuqra adac siauq son soeredne so e soviuqra ed semon mtnoC .soviuqra ed ametsis od aruturtse

.oirnib ogidc mu mbmat retnoc edop omoc meb ,.cte ,amargorp mu ed ogidc o ,otxet

:res medop soviuqra sO

soviuqrA ed sopiT

.soviuqra ed oalupinam arap )ametsis ed sadamahc( etropus iussop lanoicarepo ametsis O .omsem olep odaicnerefer e emon mu iussop oviuqra adaC oirteirporp me olep sadinifed ametsis seamrofni meussop sacigl .)samargorp e sodad( ,socisf sovitisopsid soviuqrA

euq

lanoicarepo

olep

sadaepam

sedaditne

os

.PX/0002 swodniW on e xuniL on soviuqra ed aicnreG :sosac ed odutsE .osseca ed sodotM .soviuqra ed oarepucer .sominnis e soviuqra ed otnemahlitrapmoC e otnemanezamrA .socisB sotiecnoC

8.1 Conceitos Bsicos

8. Gerncia de Arquivos

oviuqra mu res edoP

.soirusu sod seamrofni

mtnoc

:seralugeR

a matnemelpmi euq e ametsis olep soditnam soviuqra os :soirteriD

622

:os oirterid mu me saditnam sacipt seamrofnI .seraluger euq soviuqra so rasseca m eti m r e p euq seamrofni mtnoc

,lanoicarepo

ametsis

olep soditnam

,siaicepse

soviuqra os soirteriD

soirteriD

.B oviuqra mu

.oviuqra ovon mu ed oairc a etimrep :etaerC

.etnetsixe oviuqra mu animile :eteleD

.oazilitu roiretsop arap oviuqra mu erba :nepO

.osu me avatse euq oviuqra mu ahcef :esolC

.sodad ed arutiel arap oviuqra mu asseca :daeR

.oviuqra mu me sodad evercse :etirW

me sodanezamra sodad ,A oviuqra mu ed lanif on ,atnecserca :dneppA

.oviuqra mu ed emon o acort :emaneR

.oviuqra mu arap ovitanretla emon mu airc :kniL

oviuqra od oirteirporP

;oairc ed ataD

;oacifidom ed ataD

;osseca ed ataD

;osseca ed sotieriD

;sominnis ed aicntsixE

;osu ed rodatnoC

;ocsid on sodad sod oerednE

.ctE

722

sotubirta sues e oviuqra od emoN o odnetnoc oirteriD

...,oirteirporP
...

,oirteirporP sotubirtA

emoN

.riuges a sarugif san sadazitameuqse os savitanretla satsE

.oviuqra od sotubirta

:mtnoc oirterid od adartne adaC .oirterid eleuqa ecnetrep euq oviuqra rop amu ,sadartne sairv iussop oirterid mU

uo ;oviuqra od sotubirta so e emon O

so moc sodad ed aruturtse amu arap orietnop mu e oviuqra od emon O

822

oirterid ocin mu moc soviuqra ed ametsiS

oviuqrA

oviuqrA

oviuqrA

oviuqrA

oirteriD

.savitanretla satse macifilpmexe riuges a sarugif sA .sodazirotua on sosseca artnoc sodigetorp soviuqra sues mt soirusu so ,ossi moC soirusu sortuo a sotierid setse rednetse edop euq e ,osseca ed sotierid ret eved oirterid od oirteirporp o etnemos euq odnes ,oirusu rop oirterid mu revah larutan siam oazinagro A .oirusu rop oirterid mu moc uo oirusu so sodot ed soviuqra so odnetnoc oirterid ocin mu odniussop omoc odazinagro res edop soviuqra ed ametsis mU

sotubirta so arap rodatnopa mu e soviuqra ed semon odnetnoc oirteriD

sotubirtA
B

sotubirtA

922

;)oirterid oa mecnetrep

:os siapicnirp sA .soirterid ed oalupinam a soirusu soa etimrep lanoicarepo ametsis od savitimirp ed otnujnoc mU

.egassem_1usu/liam/loops/rsu/ oviuqra o aipoc o egassem_1rsu o eS .x E arap 1rsu pc 1usu/liam/loops/rsu/ xuniL odnamoc o ,liam oviuqra etnerroc os

oirterid

.etnerroc

oirterid

oa

sovitaler

sodaredisnoc

,)\,/( rodarapes o moc maemoc on euq oviuqra ed semon so sodoT

.5pac oviuqra roP od otelpmoc o ta emon a o 5pac/orvil/cmc/emoh/rsu/ ohnimac od etsisnoc ,olpmexe

.sovitaler uo sotulosba res medop soviuqra sod semon so ,aciuqrreih aruturtse amuN

.)soviuqra ed erovr amu( soviuqra ed aciuqrreih edop aruturtse adac amu odnamrof rop ,soirterid mu uo seraluger soviuqra aN

rairc

oirusu

,oirusu

oirterid

moc

oazinagro

oirusu rop oirterid mu moc soviuqra ed ametsiS

1riD

1qrA

n oirusU

3oirusU

2oirusU

1oirusU

oirteriD

.oviuqra

ziar

edsed

:sotulosbA

.etnerroc oirterid ed otiecnoc o moc etnematnuj sodazilitu :sovitaleR

;oirterid ovon mu airc :etaerC

;soviuqra mtnoc on euq oirterid mu animile :eteleD

euq soviuqra ed semon( oirterid mu ed odetnoc o atsil :tsiL

032

servil socolb ed aicnreG

.ocirfirep on ,sodad ed ocolb oa osseca o odazilaer res edop otne e odarepucer

ocolb od oeredne o ,airmem an alebat otief osseca O .)ocimdnar o s s e c a( ocsid a osseca muhnen oirssecen on ocolb mu racifitnedi

araP .)rotircsed o moc etnematnuj( airmem a arap iav alebat atse ,otreba oviuqra o odnauQ .oviuqra od rotircsed on ,alebat amu me odanezamra ocsid ed ocolb ed rodatnopa adaC :airmem an alebat moc socolb ed atsiL

.oviuqra od sodad ed socolb n - i so rerrocrep , otsi ,odajesed ocolb o ta adaedacne atsil a rerrocrep oirssecen )ocimdnar osseca( i ocolb on oamrofni adanimreted amu rasseca arap ,oulos atseN .ocolb omixrp o maeredne setyb siod ,seamrofni manezamra setyb 2201 ,k1 ed socolb moc ,olpmexe roP .ovitisopsid od socolb ed adaedacne atsil amu me sodanezamra os oviuqra mu a setnecnetrep sodad sO :adaedacne atsiL

.adazilitu on adacola aer a , otsi ,oatnemgarf a e iroirp a oviuqra od ohnamat od oanimreted a os oulos atsed samelborp siapicnirp sO .etneicife

arienam ed odil res edop oviuqra o e ratnemelpmi ed selpmis avitanretla a ts E ed on .etyb K mu ed sovitucesnoc ,missA socolb od 032 sodacola so maires arap setybK032 ovitisopsid oacolA

oviuqra

mu

arap

.oviuqra

sodad

retnoc O

augtnoc

aer

amu

acola

lanoicarepo

ametsis

:augtnoC

:res edop oapse ed oacola A .sietlov on ,socisf sovitisopsid me sodanezamra os soviuqra soa setnecnetrep sodad sO

8.2 Armazenamento e Recuperao de Arquivos

.oirterid mu ed emon o acort :emaneR

132

.oviuqra od ortsiger oriemirp on ritrap a odil res ratissecen oviuqra o ,roiretna ortsiger mu rel oirssecen rof eS .9 oremn o odasseca res a ortsiger

omixrp o acidni euq o ,)evon + n( res a assap etnerroc oisop a ,osac etseN .seroiretna sortsiger so sodot odnel atief )8 + n( ortsiger od arutiel a ,n oviuqra od etnerroc oisop a es ,olpmexe roP .seroiretna sortsiger )1 i( so rel oirssecen i ortsiger o rasseca araP .etnemlaicneqes

sodasseca res medop etnemos sodanezamra sodad so :laicneqes ossecA

.adazilitu oazinagro ed amrof ad edneped ,oavarg e arutiel ed searepo san ,odad soa osseca O .ocsid ed socolb me sodanezamra os soviuqra sod sodad sO

.stib n ed apam mu oirssecen res socolb n moc ocsid mu arap ,missA .orez rop sodapuco so e mu rop sodatneserper os servil socolb so lauq an ,ocsid od oapuco ed apam o mtnoc )stib ed apam( alebat amU :stib ed apaM

.etybM mu raeredne arap socolb siod soirssecen os ,ogoL .servil socolb ed soeredne 215 ocolb mu me odanezamra res edop ,ervil ocolb mu racifitnedi arap setyb siod e etybK1 ed socolb moc ,olpmexe roP .atsil a retnoc arap airssecen socolb ed edaditnauq a oulos atsed etneinevnocni O .sievnopsid ed atsil a aroprocnier

o ocolb mu ed oarebil a e ,sievnopsid ed atsil ad ocolb mu odnariter atief oviuqra mu arap ocolb ovon mu ed oacola A .servil socolb ed adaedacne atsil amu mtnam lanoicarepo ametsis O :servil socolb ed adaedacne atsiL

:os sadazilitu seulos sauD

o arap sodazilitu ,socirfirep son levnopsid oapse od aicnreg a arap sodazilitu sotnemidecorp ed otnujnoc mu iussop lanoicarepo ametsis O

8.3 Mtodos de Acesso


.soviuqra ed otnemanezamra

232

; )b& ,i(daer

oviuqra od laniF

oviuqra od oicnI

.oviuqra od sodad ed ocolb oriemirp on ,992 etyb o ta e 002 etyb od ritrap a ,arutiel amu me odamrofsnart srt ocigl ortsiger od arutiel a ,missA .socigl sortsiger soriemirp 01 so sodanezamra res medop oviuqra od sodad ed

ocolb oriemirp on ,setyB 001 ed socigl sortsiger moc oviuqra mu e etybK mu ed socolb moc ocsid mu odnaredisnoC .ocigl ortsiger ed oremn mu a ocisf oeredne ed mu aicossa ,lanoicarepo on a c i s f ametsis olep adatucexe ad ,oamrofsnart

onuf

amU

.ocsid

oazilacol euq

aus

etnemetnednepedni me etnemacigol ossecA

,etnematerid sodazinagro

sodasseca os oviuqra

res oa

medop

sortsiger sodad sO

setnecnetrep

:oterid

laicneqeS ossecA ed oviuqrA

osseca ed oisoP oviuqra oviuqra od laniF od oicnI

332

:os xuniL olep sodatropus soviuqra ed sametsis snuglA .xiniM soviuqra ed ametsis on adatnemelpmi onuf a adatucexe

res ,xiniM on odareg oviuqra mu rof eS .SOD-SM oa etnednopserroc onuf a adatucexe res ,SOD-SM on odareg oviuqra mu ed arutreba ad es-odnatarT .etnednopserroc soviuqra ed ametsis oa SFV olep adaeredne res ,nepo olpmexe rop ,ametsis ed adamahc amU .soviuqra ed ametsis ed opit od etnemetnednepedni ,emrofinu ecafretni amu odnecerefo ,soviuqra ed ametsis oa sadanoicaler ametsis od sadamahc sa sadot atarT .soirusu ed samargorp so moc soviuqra ed ametsis od ecafretni a atnemelpmi SFV O .xuniL od lenrek on soviuqra ed sametsis setnerefid ed aicntsixe a etimrep e xuniL od ogidc oa odaroprocni iof euq erawtfos od levn mu SFV O

.)SFV( metsyS eliF lautriV o odairc iof ,levssop essof ossi euq araP .xuniL oa sodaroprocni e sodivlovnesed marof soviuqra ed sametsis sortuo ,seatimil satse a odiveD .)setyBM46 ( soviuqra sod ohnamat oa e )seretcarac 41 ed omixm( soviuqra sod semon sod ohnamat oa setnerefer ,seirtser sairs aussop euq ,xiniM od soviuqra ed ametsis o etnemos avatropus ,osrev ariemirp aus mE .7891 me muabmenaT rop odivlovnesed lanoicarepo ametsis ,xiniM on odaesab odatnemelpmi iof xuniL o ,megiro aus mE

ocolb

ed

oremn

me

ortsiger

ad odatluser o i osseca ed oisop a ,daer oarepo an ,amica arugif aN

oteriD ossecA ed odotM

8.4 Gerncia de Arquivos no Linux

.ocolb od ortned otnemacolsed od ocigl oremn od oamrofsnart

.xiniM od soviuqra ed ametsiS

.SFTN ,TAFV ,SOD-SM

;SFresieR ,3txE ,2txE

432

ed sotierid ,ovitisopsid od rodacifitnedi ,stib me ocolb od ohnamat ,setyb me ocolb od ohnamat omoc siat ,soviuqra ed ametsis o erbos seamrofni mtnoc kcolbrepus aruturtse A .)(repus_daer onuf alep odazilaicni

)kcolbrepus aruturtse( ocolbrepus O .adatnom res eved soviuqra ed ametsis od aicntsni avon amu odnauq adamahc euq ,)(repus_daer onuf a e )2txe .xe( soviuqra ed ametsis od emon o mtnoc atsil ad odon adac edno ,)oxiaba arugif( soviuqra ed ametsis ed adaedacne atsil amu mtnam xuniL O .odazilitu res assop euq setna ,odatnom res eved soviuqra ed ametsis o odoT

smetsys eliF

:os SFV olep sodazilitu os euq sotejbo sO

.otejbo od sodotm soa mednopserroc euq senuf sad soeredne so mtnoc euq sopmac snugla meussop sodad ed saruturtse sa ,sotejbo a adatneiro megaugnil amu me odatnemelpmi iof on omoC .sodad ed saruturtse sa malupinam euq sodotm so e sodad ed saruturtse sa moc ,sotejbo a oatneiro ed oledom o moc adasnep iof SFV od oatnemelpmi A

.)sortemrap( daer_po_elif ateridni adamahc amun amrofsnart es e ,ocifcepse ametsis od daer onuf a arap rodatnopa o azilacol )daer_sys( daer ametsis ed adamahc amu ,missA .ocifcepse oviuqra ed ametsis od senuf sa arap serodatnopa iussop euq po_f odamahc opmac mu mtnoc euq ,elif adamahc sodad ed aruturtse amu rop odatneserper oviuqra mu ,oledom etse moC .soviuqra ed ametsis ed mumoc oledom mu atnemelpmi SFV O

.ctE

smetsys eliF

eliF

edonI

yrtneD

532

,seretcarac 51 ta ,soirterid ed soneuqep semon etnemoS .ecnamrofrep ed setseuq rop etnemos etsixe euq e sodasseca etnemumoc siam soirterid so mtnam euq ,soirterid ed ehcac amu mtnam SFV O

yrtneD

;))epip(ofif

os seamrofni sA .soviuqra ed ametsis o erbos e oviuqra o erbos seamrofni mtnoC .oviuqra od rotircsed o edonI O

edonI

.cte ,oviuqra oa sosseca ed oremn o ,osseca ed opit o ,oviuqra o atneserper euq edon-i o arap rodatnopa ,osseca ed sotierid ,)odasseca etyb omitl( oviuqra od etnerroc oisop mezaF :seamrofni setniuges sa aruturtse atsed etrap

.adazilaer res reved oarepo a lauq ad ritrap a oviuqra on etnerroc

oisop a ,ossecorp adac arap ,mtnam elif aruturtse a ,oviuqra od sotnop setnerefid me atircse/arutiel ed searepo ratucexe arap oviuqra omsem mu rasseca ajesed sossecorp ed oremn otrec mu odnauQ .sossecorp setnerefid rop oviuqra mu a odahlitrapmoc osseca o ritimrep arap etsixe aruturtse atsE

.soviuqra ed ametsis od ziar edon-i o e odatnom iof soviuqra ed ametsis o lauq on oirterid ,oacifidom amitl ad atad ,osseca

;oirteirporP

,laicepse eretcarac ,laicepse ocolb ,oirterid ,oirnidro( oviuqra ed opiT

;osseca ed sotieriD

;oacifidom ,osseca

ed sataD

eliF

;sknil ed oremN

;)oeridni alpud ,oeridni ,oterid( socolb ed atsiL

632

os e sodasseca res matissecen mbmat soiridemretni soirterid so matneserper euq sedoni so edoni mu rasseca araP .odnazilitu

tse o oirusu ortuo mu euq odnacidni ,odatnemercni osu ed rodatnoc o ,odartnocne edoni o eS .adasiuqsep sedoni ed ehcac a ,odnartnocne oN .soirterid ed ehcac an acifirev otnemidecorp etse ,odasseca res eved edoni mu euq zev adaC .edoni mu ed acsub ed otnemidecorp o arap e ziar oirterid o arap rodatnopa mu iussop soviuqra ed ametsis adac ed ocolbrepus aruturtse A .odatucexe res eved ,soviuqra ed ametsis ed opit adac arap ocifcepse euq ,edoni mu ed acsub ed otnemidecorp o ,ossi araP .soiridemretni soirterid so sodot odnasseca ,oviuqra o ta ohnimac o rerrocrep atissecen SFV o ,oviuqra mu ed edoni mu razilacol araP

.ovitisopsid od rodacifitnnedi o moc e edoni od oremn o moc otief hsah evahc atsed oluclc O .hsah evahc ed rolav omsem ed sedoni ed atsil amu arap rodatnopa mu odnet adartne adac moc ,hsah alebat amu omoc adatnemelpmi sedoni ed ehcac A .ecnamrofrep me ahnag ametsis o ,ehcac an odartnocne e odasseca res atissecen edoni mu euq zev adaC .sedoni ed ehcac amu mbmat iussop SFV o ,sodazilitu siam soirterid sod ehcac amu airmem an retnam ed mlA

.oirterid od emon o e ovitisopsid od oremn o azilitu SFV o hsah evahc ad oluclc o araP .hsah evahc ed rolav omsem o meussop euq sadartne ed atsil amu arap atnopa adartne adac edno ,hsah alebat amu ed etsisnoc soirterid ed ehcac A

.ehcac an odartnocne res ri ,odasseca rof oviuqra etse euq zev amixrp A .1onula oirterid o arap amu e onula oirterid o arap amu ,emoh oirterid o arap amu ,resu oirterid o arap amu ,/ oirterid o arap amu ,ajes uo ,emanhtap od etnenopmoc adac

arap yrtned aruturtse amu rairc ri ametsis o ,1onula/onula/emoh/resu/ oviuqra o rasseca ejesed ossecorp mu euq odnopuS .edoni mu a adaicossa tse yrtned aruturtse amU .asseca ossecorp mu euq oirterid uo oviuqra ed emon o odot arap yrtned aruturtse amu airc ametsis O .yrtned aruturtse amu me odamrofsnart ,airmem a a arap adil oirterid mu ed adartne amu odnauQ .ehcac atsen soditnam os

732

2txe od ocolbrepus O

.ahlaf ed osac me oarepucer arap ,soviuqra ed ametsis od sacitrc seamrofni sa sadacilper os opurg ad c mE .socolb ed sopurg me apuco euq acigl oitrap a edivid 2txe O .ocisf ocolb etnednopserroc on ocigl ocolb od oamrofsnart a rezaf revird od onuf .socigl socolb moc atart 2txe O

;oirterid

:seamrofni setniuges sa iussop adartne adac e sadartne ed atsil amu iussop oirterid mU .soviuqra ed ametsis mu me soviuqra soa osseca ed ohnimac o retnam arap sodasu siaicepse soviuqra os soirterid sO .edoni mu etnemos rop otircsed oviuqra adaC .oviuqra od opit o e osseca ed satad sa e soviuqra

oa osseca ed sotierid ,oviuqra od sodad ed socolb so iussop edoni mU .sedoni rop adinifed soviuqra ed ametsis od aruturtse A .soviuqra ed sametsis setnerefid sotium ratropus xuniL oa etimrep euq ,lanoicarepo ametsis od soviuqra ed sametsis so arapes euq ,SFV o odaroprocni mbmat iof ,xuniL oa 2txe od oaroprocni a levssop ranrot araP .xuniL oa odaroprocni iof 2txe o ,3991 mE .ecnamrofrep ed samelborp avatneserpa mrop ,txe o iof xuniL o arap odivlovnesed soviuqra ed ametsis oriemirp O

2txe soviuqra ed ametsis O

.sodazilitu siam sedoni so etnemos ehcac an retnam arap ,URL omtirogla u azilitu SFV O .sedoni ed ehcac an sodacoloc

on adartne a etnednopserroc edoni o arap rodatnopa :edonI

;setyb me ,oirterid od adartne ad ohnamat :emon od ohnamaT

.oirterid od adartne an ecerapa euq oviuqra od emon :emoN

832

:seamrofni setniuges sa mtnoc socolb ed opurg ed rotircsed O .sahlaf ed osac me oarepucer arap ,opurg adac me adacilper alebat atsE .socolb ed sopurg ed alebat a odniutitsnoc ,etnemlaicneqes sodanezamra os socolb ed opurg ed serotircsed so sodoT .socolb ed opurg mu revercsed arap odazilitu

opurg ed rotircseD

.soviuqra ed

;soviuqra

;soviuqra

;ocolbrepus etneserp o mtnoc euq

.2txe soviuqra ed ametsis mu ed ocolbrepus od atart es euq racifirev soviuqra

:seamrofni setniuges sa ,sartuo ertne ,iussop ocolb repus O .ahlaf ed osac me adasu res arap ,ocolbrepus od aipc

amu iussop socolb ed opurg adac sam ,odatnom soviuqra ed ametsis o odnauq airmem a arap odil 0 ocolb od ocolbrepus o ,etnemlamroN .soviuqra ed ametsis o erbos seamrofni mtnoc ocolb repus O

ed ametsis o atnom euq otnemidecorp oa etimrep :ocigm oremN

socolb ed

opurg od oremn o mtnoc :socolb ed opurg od oremN

.setyb me ,ocolb od ohnamat mtnoc :ocolb od ohnamaT

;socolb ed opurg rop socolb ed oremn mtnoc :opurg rop socolB

ed ametsis on servil socolb ed oremn o mtnoc :socolb eerF

ed ametsis on servil sedoni ed oremn o mtnoc :sedoni eerF

ametsis od edoni oriemirp o arap rodatnopa mu mrtnoc :edoni tsriF

932

sodad ed socolb ed

;)oterid(

:seamrofni setniuges sa ,sartuo ertne ,iussop 2txe edoni mU .sodapuco e ervil sedoni racifitnedi ametsis oa etimrep euq ,stib ed apam mu rop sodaicnereg os socolb ed opurg mu ed sedoni sO .2txe on oviuqr amu erbos seamrofni sa iussop edoni O

2txe on edoni O

.socolb ed opurg

;socolb ed opurg

;socolb ed opurg od sedoni ed alebat a

anezamra

;sedoni ed oarebil/oacola an odasu .socolb ed opurg o arap sedoni

;socolb ed oarebil e oacola arap odazilitu .socolb ed opurg o

arap socolb ed oacola ed apam o mtnoc :socolb ed stib ed apaM

ed oacola ed stib ed apam o anezamra :sedoni ed stib ed apaM

euq ocolb oriemirp od oremn o mtnoc :sedoni ed alebaT

on servil socolb ed oremn o mtnoc :servil socolb ed oremN

on servil sedoni ed oremn o mtnoc :servil sedoni ed oremN

;oirteirporP

;sessimreP

;oviuqra ed opiT

;oviuqra od ohnamaT

;osseca ,oacifidom ,oairc :sataD

sodad ed socolb soriemirp 21 sod soeredne :sodad ed socolB

serodatnopa mtnoc euq ocolb mu arap atnopa :oeridni ed ocolB

042

.otnemanezamra ed oapse ed oicdrepsed me acilpmi euq o ,odacola retsulc mu oret mbmat

BK4 ed sonem moc soviuqrA .SFTN olep adasu ,oacola ed edadinu a retsulc mU .BK4 ed odatamrof ovon ocsid mu me retsulc arap ordap

o ,etnerefid ohnamat mu acificepse on oirusu o eS .ocsid od oatamrof an odinifed retsulc sod ohnamat o e ,zev adac ed adazilitu socolb ed edaditnauq a , otsi ,socigl sretsulc me ocsid o edivid SFTN O

.anaruges e edadilibixelf ,ecnamrofrep atla atneserpa e 0991 sona son tfosorciM alep odairc ioF .sonredom swodniW sianoicarepo sametsis so sodot me odazilitu e TN swodniW o arap

odivlovnesed soviuqra ed ametsis o )metsyS eliF ygolonhceT weN( SFTN O

ed ametsis o ,amrof atseD .ocsid me sadavarg otne os sadazilaer on omoc sadacram gol on martnocne es euq searepO .odasilana

gol o rarepo a ratlov ametsis o odnauQ .aigrene ratlaf ,olpmexe rop ,es macrep es ocsid me sadavarg etnemavitefe marof on adnia euq e sadazilaer odnes otse euq searetla euq etimrep gnilanuoj O

e soviuqra ed ametsis on sadautefe os searetla satsE .gol ed oviuqra odamahc ,laicepse oviuqra mu me soviuqra ed ametsis on sadazilaer searetla sa anezamra euq acinct amu gnilanruoJ .gnilanruoj ed edadicapac moc ,2txe soviuqra ed ametsis mu etnemlaicnese 3txe .3txe soviuqra ed ametsis o meussop xuniL od sesrev samitl sA

8.5 Gerncia de Arquivos no Windows 2000/XP


.sodad ed adrep ed edadilibaborp a iunimid soviuqra .odivomer )lanruoj( gol o otne

.oeridni ed sievn siod :oeridni alpud ed ocolB

.oeridni ed sievn srt :oeridni alpirt ed ocolB

142

lanoicarepo ametsis o odnauq ,ahlaf amu rop adipmorretni res oasnart ad osac oN .uotelpmoc es oasnart a euq )gol on( artsiger lanoicarepo

ametsis o ,gol on sadartsiger os oasnart a setnerefer searepo sa sadot eS .gol oviuqra mu me adavarg ale adatucexe oasnart ad etrap amu euq zev adac :etniuges o omsinacem od otnemanoicnuf O

.adatucexe on uo etnematelpmoc adatucexe oasnart amu ,edadicimota ed otiecnoc o moC .setnetsisnoc soviuqra

so retnam a arienam ed ,etnemacimota sadatucexe res meved euq searepo ed otnujnoc mu oasnart amU .seasnart ed otiecnoc o odnazilitu sahlaf a aicnrelot atnemelpmi ,lanoicasnart soviuqra ed ametsis mu SFTN O

.oviuqra od sodad siamed so sodanezamra otse edno ,lareg otnemanezamra ed aer a arap rodatnopa mu moc etnematnuj ,TFM an odanezamra tse sodad sod etrap amu ,sosac sod airoiam aN .soneuqep soviuqra arap levssop etnemos otsI .TFM an odanezamra res

oviuqra etse ,TFM ortsiger mu ed oa roirefni ohnamat merevit sodad sues so siam ,oviuqra mu ed sotubirta sodot eS .retsulc mu ed ohnamat o etnemacipit TFM alebat an ortsiger mu ed ohnamat O .otnemanezamra ed aer an sodanezamra os setnediser on so e TFM an sodanezamra os setnediser sotubirtA .setnediser on uo setnediser res medop sotubirta sO

.soviuqra sod sodad mbmat sodanezamra os TFM ad sortsiger soN .cte ,osseca omitl od atad ,oacifidom

ed atad ,oviuqra od oairc ed atad a ,osseca ed sotierid ,)seretcarac 552 omixm on( oviuqra od emon o os TFM an sodanezamra oviuqra

mu ed sotubirta snuglA .otnemanezamra ed aer an odanezamra ,oirterid mu uo onalp oviuqra res edop euq ,oviuqra mu ed sotubirta so mtnoc euq ortsiger mu adartne adac me ,mtnoc euq alebat amu TFM A

.ale arap sadacola ores ocsid od saer sartuo ,oapse ues o etnemlatot rapuco TFM a eS .otnemanezamra ed lareg aer a arap setnatser

%88 so odnacif ,TFM a arap odavreser oapse od %21,odatamrof ocsid mu odnauQ .otnemanezamra ed lareg aer amu e )TFM( elbaT eliF retsaM adanimoned ,etrap amu rop odamrof ,ociuqrreih ametsis mu SFTN O

242

.soirterid ed odetnoC ratsiL e arutieL sessimrep sa euq sotierid somsem so iussop elE .odnagevan tse siauq son soirterid soa osseca ed ossimrep ahnet on oirusu o euq omsem ,soviuqra e soirterid sortuo a ragehc arap oirterid on me ragevan oditimrep : ratucexe e reL

.oirterid oa setnecnetrep soviuqra sod emon o reV

:odetnoC ratsiL

.oirterid od sessimrep sa e onod o razilausiv e oirterid od sotubirta raretla ,oirterid od ortned soviuqra sovon rairC :oavarG

oirterid od sotubirta e sonod ,sessimrep ribixe e oirterid mu ed odetnoc ratsiL :arutieL

:os sessimrep sa oirterid araP .ametsis od rodartsinimda o e opurg o ,oviuqra od oirteirporp o arap os sessimrep sA .onalp oviuqra ed levn a e oirterid ed levn a sessimrep ed oinifed a etimrep euq soviuqra soa osseca ed oetorp ed omsinacem mu iussop SFTN O

.pukcab ed oarepo amitl a edsed sodacifidom soviuqra ravlas arap lanruoJ egnahC od mazilitu es ,olpmexe rop ,pukcab ed samargorP .oviuqra etse a odanoicida odacifidom uo odateled ,odairc oviuqra mu euq erpmeS .sadirroco searetla sa e oviuqra od emon o mtnoc e )rebmuN ecneuqeS etadpU( oremn mu rop adacifitnedi oviuqra on adartne adaC .soviuqra ed ametsis on sadirroco searetla sa anezamra lauq on ,lanruoJ egnahC o ,laicepse oviuqra mu mtnam mbmat SFTN O

.edadiroirp axiab ed ossecorp mu rop ,sopmet me sopmet ed ,gol oviuqra on sadavarg os euq ,oasnart ed lanif ed sacram sa sadavarg os lauq an ehcac airmem amu iussop swodniW o ,daehrevo o riunimid a arienam eD

.etnetsisnoc etnemavon ametsis o ranrot iav euq o ,satiefsed sadazilaer searepo sa oret maratelpmoc es on euq seasnarT .gol oviuqra o razilana ri ratucexe a etnemavon raemoc

342

.lanigiro TFM an ahlaf ed osac me adasu res arap ,TFM ad sadartne

.oviuqra o arap odacola ortsiger ortuo ,ortsiger mu me etnetsixe oapse o euq roiam oviuqra od sodad ed socolb sod oazilacol a erbos seamrofni sa euq me osac oN .emulov on etnetsixe oviuqra adac arap ,adartne amu ortsiger mu , otsi

:os sodaDateM soviuqra sO .TFM ad )sortsiger( sadartne 61 sariemirp sa mapuco e ,odatamrof ocsid mu odnauq sodairc os soviuqra setsE .SFTN od aicnreg a sadanoicaler seamrofni meussop

euq ,sodadateM ed sodamahc ,siaicepse soviuqra snugla mtnam SFTN O

.sessimrep sartuo sa sadidecnoc sea siamed sa sadot razilaer redop ed mla ,oviuqra od onod es-ranrot e sessimrep raretla edop oirusu O :latot elortnoC

ratucexe e reL e ravarG sessimrep sad sea sa sadot ed mla ,oviuqra ranimile e racifidoM :oacifidoM

.arutieL ossimrep ad sea sa sadot razilaer e samargorp ratucexE :oucexe e arutieL

ad sessimrep sa e onod o razilausiv e atsap ad sotubirta raretla ,oviuqra o erbos emon omsem o moc oviuqra mu ravarg edop oirusu O :oavarG

.sotubirta e onod ,sessimrep ribixe ,oviuqra o reL

:os soviuqra arap sessimrep sA

mtnoc euq ,oviuqra mu TFM a :TFM$ :0 ortsigeR

sariemirp 61 sad aipc amu anezamra :rriMTFM$ :1 ortsigeR

.atsap :arutieL

.SFTN od seasnart ed gol o mtnoC :eliFgoL$ :2 ortsigeR

442

.cte ,sotejbo

edocinU otamrof o arap soviuqra ed semon ed osrevnov

.emulov on soviuqra so sodot

.ezilitu so on soviuqra ed ametsis o euq ritnarag arap ,emulov od

.ale arap rodatnopa mu

.oacola arap sievnopsid otse siauq e otnemom on sodazilitu otse sretsulc

.emulov od )aiuqrareh

.SFTN satsap e soviuqra me sodazilitu meres arap sievnopsid

.emulov od oairc ed atad e SFTN od osrev omoc

,is me emulov o erbos seamrofni mtnoc :emuloV$

:3 ortsigeR

sotubirta ed sopit sod oinifed a mtnoC :feDrttA$

:4 ortsigeR

ad opot( ziar oirterid o arap rodacidni mu mtnoC :.$

:5 ortsigeR

siauq acidni euq stib ed apam o mtnoc :pamtiB$

:6 ortsigeR

uo emulov od toob ed ogidc od aipc mtnoC :tooB$ :7 ortsigeR

sosoutiefed sretsulc sod atsil amu mtnoC :sulCdaB$

:8 ortsigeR

arap anaruges ed serotircsed so mtnoc :ERUCEs$ :90 ortsigeR

ed seamrofni mtnoc euq alebaT :esaCpU$ :01 ortsigeR

ed serodacifitnedi ,ocsid ed satoc arap odasu :dnetxE$ :11 ortsigeR

.orutuf osu arap sodavreser :51 a 21 sortsigeR

Exerccios

542

.oirterid opit od soviuqra me sadatucexe searepo saud ed otnemanoicnuf o avercseD .oviuqra mu ed arutreba ed oarepo a avercsed e ,soviuqra soa setnerefer ,ametsis olep saditnam res meved euq seamrofni sa moc tcurts amu anifed ,ociuqrreih soviuqra ed ametsis mu odnaredisnoC .2 .3

.soviuqra ed rotircsed o euq ,edon-I mu ed aicntsixe a eredisnoC .ociuqrreih oviuqra od soviuqra arutreba ed a ametsis mu me cod.posis/sforp/emoh/rsu/ ,avercseD .1

,etnemacifarg

odnacifilpmexe