02.11.2013 Views

Systemsoftware

Systemsoftware

Systemsoftware

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Beispiel 3: Verwaltung eines Ressourcen-Pools<br />

MONITOR DiscPool (int Zahl)<br />

enum<br />

{frei,belegt} DiscStatus[N];<br />

int busy; /*Zahl Laufwerke*/<br />

Condition nonbusy;<br />

ENTRY int GetDisc() {<br />

int i;<br />

i=1;<br />

if (busy==N)<br />

nonbusy.Wait();<br />

while (DiscStatus[i]==belegt)<br />

i++;<br />

DiscStatus[i]=belegt;<br />

busy++;<br />

return i;<br />

}<br />

ENTRY PutDisc(int UsedDisc) {<br />

DiscStatus[UsedDisc]=frei;<br />

busy--;<br />

nonbusy.Signal();<br />

}<br />

INIT {<br />

N=...; /*Anzahl Laufwerke*/<br />

DiscStatus[0]=frei;<br />

DiscStatus[1]=frei;<br />

.....<br />

DiscStatus[N-1]=frei;<br />

busy=0;<br />

}<br />

END DiscPool<br />

<strong>Systemsoftware</strong> - Lektion X 11<br />

Beispiel 4: Reader-Writer-Problem (Reader-Bevorzugung)<br />

MONITOR ReadWrite<br />

int ReadCount, Writeflag;<br />

Condition OKtoRead,OKtoWrite;<br />

ENTRY StartRead() {<br />

Readcount++;<br />

if (Writeflag==1)<br />

OKtoRead.Wait();<br />

OKtoRead.Signal();<br />

}<br />

ENTRY EndRead() {<br />

Readcount--;<br />

if (Readcount==0)<br />

OKtoWrite.Signal();<br />

}<br />

ENTRY StartWrite() {<br />

if ((Readcount>0)¦¦<br />

(Writeflag==1))<br />

OKtoWrite.Wait();<br />

Writeflag=1;<br />

}<br />

ENTRY EndWrite() {<br />

Writeflag=0;<br />

if (OKtoRead.Status()>0)<br />

OKtoRead.Signal();<br />

else OKtoWrite.Signal();<br />

}<br />

INIT {<br />

Readcount=0;<br />

Writeflag=0;<br />

}<br />

END ReadWrite<br />

<strong>Systemsoftware</strong> - Lektion X 12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!