Difference between revisions of "ProvaTeorica 2013.05.30"

From Sistemi Operativi
Jump to navigation Jump to search
Line 8: Line 8:
 
<h2> Esercizio g.2 </h2>
 
<h2> Esercizio g.2 </h2>
 
[[File:Holt.png]]
 
[[File:Holt.png]]
 +
 +
 +
<syntaxhighlight lang="C">
 +
monitor eventp
 +
{
 +
typedef struct EP
 +
{
 +
unsigned int value;
 +
condition okNotNull;
 +
condition okToAdd;
 +
intqueue q;
 +
}
 +
}
 +
 +
procedure entry EP* create(unsigned value)
 +
{
 +
EP *ep = new EP(value);
 +
eps.enqueu(ep);
 +
return ep;
 +
}
 +
 +
procedure entry write(EP *d,unsigned value)
 +
{
 +
if(d.value+value > d.value.size()|| !d.q.empty()) {
 +
d.q.enqueue(value);
 +
d.okToAdd.wait();
 +
d.q.dequeue();
 +
}
 +
d.value = d.value + value;
 +
if (d.q.top()+value <= d.value.size())
 +
d.okToAdd.signal();
 +
else
 +
d.okNotNull.signal();
 +
}
 +
 +
// MAXINT - currentvalue < value
 +
procedure entry unsigned int read(EP *ep)
 +
{
 +
if(!ep.value)
 +
ep.okNotNull.wait();
 +
unsigned int toReturn = ep.value;
 +
ep.value = 0;
 +
ep.okToAdd.signal();
 +
return toReturn;
 +
}
 +
<syntaxhighlight>

Revision as of 16:29, 19 May 2014

Testo del compito

Esercizio g.1

PUNTO A: (7+256+(256^2)+(256^3))*1kb =16.843.015kb quindi approssimativamente 16MB

PUNTO B: blocco indiretto triplo -> primo livello di idirizzamento 256 esimo blocco -> secondo livello di indirizzamento 256 esimo blocco -> terzo livello di indirizzamento al blocco 100000. Qundi in totale 4 blocchi

Esercizio g.2

Holt.png


<syntaxhighlight lang="C"> monitor eventp { typedef struct EP { unsigned int value; condition okNotNull; condition okToAdd; intqueue q; } }

procedure entry EP* create(unsigned value) { EP *ep = new EP(value); eps.enqueu(ep); return ep; }

procedure entry write(EP *d,unsigned value) { if(d.value+value > d.value.size()|| !d.q.empty()) { d.q.enqueue(value); d.okToAdd.wait(); d.q.dequeue(); } d.value = d.value + value; if (d.q.top()+value <= d.value.size()) d.okToAdd.signal(); else d.okNotNull.signal(); }

// MAXINT - currentvalue < value procedure entry unsigned int read(EP *ep) { if(!ep.value) ep.okNotNull.wait(); unsigned int toReturn = ep.value; ep.value = 0; ep.okToAdd.signal(); return toReturn; } <syntaxhighlight>