ProvaTeorica 2013.02.15

From Sistemi Operativi
Revision as of 15:30, 2 May 2014 by Stanislao (talk | contribs)
Jump to navigation Jump to search

Testo del compito


Esercizio 1

/*
Esercizio c.1: (a) Scrivere un monitor dualwriter che realizzi un doppio buffer limitato (ogni buffer ha ampiezza
BUFSIZE) che consenta a uno scrittore di scrivere contemporaneamente due elementi che andranno rispettivamente
nel primo e nel secondo buffer. Le letture :
 procedure entry void write(type1 e1, type2 e2);
 procedure entry type1 read1();
 procedure entry type2 read2();
La funzione write deve attendere che ci sia spazio in entrambi i buffer. 
La funzione read attende che vi sia almeno un elemento nel buffer indicato
*/
monitor dualwriter
{
	type1* buffer1;
	type2* buffer2;
	condition oktowrite,oktoread1, oktoread2
	procedure entry void write (type1 e1, type2 e2)
	{
		if (sizeof(type1)>=BUFSIZE || sizeof(type2)>=BUFSIZE)
			oktowrite.wait();
		buffer1.push(e1);
		buffer2.push(e2);
		oktoread1.signal();
		oktoread2.signal();
	}
	
	procedure entry type1 read1()
	{
		if (sizeof(buffer1)==0)
			oktoread1.wait();
		buffer1.pop();
		if (sizeof(buffer2)<BUFSIZE)
			oktowrite.signal();
	}
	
	procedure entry type2 read2()
	{
		if (sizeof(buffer2)==0)
			oktoread2.wait();
		buffer2.pop();
		if (sizeof(buffer1)<BUFSIZE)
			oktowrite.signal();
	}
}

-stefano92

Esercizio g.1

RoundRobin2cpu.png