Difference between revisions of "ProvaTeorica 2014.02.22"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Line 35: | Line 35: | ||
| 	return tmp; | 	return tmp; | ||
| 	} | 	} | ||
| + | } | ||
| + | |||
| + | </syntaxhighlight> | ||
| + | |||
| + | Esercizio c.1 | ||
| + | |||
| + | <syntaxhighlight lang="C"> | ||
| + | |||
| + | |||
| + | condition oktowrite, oktoread, oktolog ; | ||
| + | queue buffer = MAXELEM ; | ||
| + | queue Llogger ; | ||
| + | |||
| + | monitor bbwl | ||
| + | { | ||
| + |  procedure entry write (altype elem) | ||
| + |  { | ||
| + | 	if (buffer.length >= MAXELEM) | ||
| + | 		oktorite.wait() ; | ||
| + | 	 buffer.enqueue(elem); | ||
| + |      oktolog.signal () ;	 | ||
| + |  } | ||
| + | |||
| + | procedur entry logger()                 # logger deve tenere traccia di tutti i pacchetti transitati mettendoli in una sua memoria. | ||
| + |  { | ||
| + | 	if (buffer.length == 0) | ||
| + | 		oktolog.wait(); | ||
| + | 	 Llogger.enqueue(buffer.front())    # restituisci il valore in testa di buffer e inseriscilo in coda a Llogger | ||
| + | 	 ok toread.signal() ; | ||
| + |  } | ||
| + | |||
| + |  procedure entry read()  | ||
| + |  { | ||
| + | 	if (buffer.length == 0) | ||
| + | 		oktoread.wait(); | ||
| + | 	 buffer.dequeue()                   # restituisci il valore in testa di buffer e rimuovilo. | ||
| + | 	 oktowrite.signal() ; | ||
| + |  } | ||
| } | } | ||
Revision as of 17:09, 30 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.1
condition oktowrite, oktoread, oktolog ;
queue buffer = MAXELEM ;
queue Llogger ;
monitor bbwl
{
 procedure entry write (altype elem)
 {
	if (buffer.length >= MAXELEM)
		oktorite.wait() ;
	 buffer.enqueue(elem);
     oktolog.signal () ;	
 }
procedur entry logger()                 # logger deve tenere traccia di tutti i pacchetti transitati mettendoli in una sua memoria.
 {
	if (buffer.length == 0)
		oktolog.wait();
	 Llogger.enqueue(buffer.front())    # restituisci il valore in testa di buffer e inseriscilo in coda a Llogger
	 ok toread.signal() ;
 }
 procedure entry read() 
 {
	if (buffer.length == 0)
		oktoread.wait();
	 buffer.dequeue()                   # restituisci il valore in testa di buffer e rimuovilo.
	 oktowrite.signal() ;
 }
}
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