Difference between revisions of "ProvaTeorica 2014.02.22"
Jump to navigation
Jump to search
| Line 38: | Line 38: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | Esercizio c.2 | ||
| + | |||
| + | alpha(x,y): <x=4, y=sqrt(x)> | ||
| + | |||
| + | il valore che viene salvato in y è sempre 2, quindi non va bene. | ||
| + | |||
| + | bravo(x,y): <y=sqrt(x), x=4> | ||
| + | |||
| + | xi yi xf yf | ||
| + | 0 0 4 0 | ||
| + | 0 1 4 1 | ||
| + | 1 0 4 1 | ||
| + | 1 1 4 1 | ||
| + | |||
| + | il valore iniziale di x viene salvato in y, quindi va bene. | ||
| + | |||
| + | charlie(x,y): <y=sqrt(x), x=4*y> | ||
| + | |||
| + | Anche questo va bene, per le stesse ragioni di bravo. | ||
| + | |||
| + | delta(z,t): <z=z xor t, t=z xor t> | ||
| + | |||
| + | zi ti zf tf | ||
| + | 0 0 0 0 | ||
| + | 0 1 1 0 | ||
| + | 1 0 1 1 | ||
| + | 1 1 0 1 | ||
| + | |||
| + | Il valore iniziale di z viene salvato in t, quindi va bene. | ||
| + | |||
| + | Esercizio g.1 | ||
| + | |||
| + | Sia n=3 il numero di pagine mantenute in memoria | ||
| + | a) 123456789123456789 | ||
| + | |||
| + | MIN = MINNUM | ||
| + | 11144777 | ||
| + | 2225588 | ||
| + | 333669 | ||
| + | |||
| + | b) 145231231231231... | ||
| + | |||
| + | MINNUM | ||
| + | |||
| + | 111232123 | ||
| + | 44444444 | ||
| + | 5555555 | ||
| + | |||
| + | MIN | ||
| + | 111111111 | ||
| + | 44222222 | ||
| + | 5333333 | ||
Alessandro | Alessandro | ||
Revision as of 11:42, 21 May 2014
Testo: [1]
Esercizio c.1
monitor bbwl {
condition oktowrite;
condition oktolog;
condition oktoread;
int logging = 0;
queue q;
procedure entry write (eltype elem) {
if (q.length() == MAXELEM || logging)
oktowrite.wait();
q.enqueue (elem);
logging = 1;
oktolog.signal();
}
procedure entry eltype log() {
if (q.length == 0)
oktolog.wait();
eltype tmp = q.top();
logging = 0;
oktoread.signal();
return tmp;
}
procedure entry eltype read() {
if (q.length == 0 || logging)
oktoread.wait();
eltype tmp = q.dequeue();
oktowrite.signal();
return tmp;
}
}
Esercizio c.2
alpha(x,y): <x=4, y=sqrt(x)>
il valore che viene salvato in y è sempre 2, quindi non va bene.
bravo(x,y): <y=sqrt(x), x=4>
xi yi xf yf 0 0 4 0 0 1 4 1 1 0 4 1 1 1 4 1
il valore iniziale di x viene salvato in y, quindi va bene.
charlie(x,y): <y=sqrt(x), x=4*y>
Anche questo va bene, per le stesse ragioni di bravo.
delta(z,t): <z=z xor t, t=z xor t>
zi ti zf tf 0 0 0 0 0 1 1 0 1 0 1 1 1 1 0 1
Il valore iniziale di z viene salvato in t, quindi va bene.
Esercizio g.1
Sia n=3 il numero di pagine mantenute in memoria a) 123456789123456789
MIN = MINNUM 11144777
2225588 333669
b) 145231231231231...
MINNUM
111232123
44444444 5555555
MIN 111111111
44222222 5333333
Alessandro