ProvaTeorica 2013.02.15

From Sistemi Operativi
Revision as of 16:22, 13 May 2014 by Stanislao (talk | contribs)
Jump to navigation Jump to search

Testo del compito


Esercizio c.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




monitor dualwriter{
	queue buffer1;
	queue buffer2;
	condition oktowrite;
	condition oktoread1;
	condition oktoread2;
	
	procedure entry void write(type1 e1, type2 e2){
		if((buffer1.len() == BUFSIZE) || (buffer2.len() == BUFSIZE)) /*se uno dei due buffer è pieno non puoi inserire*/
			oktowrite.wait();
		
		buffer1.enqueue(e1);
		buffer2.enqueue(e2);
		
		oktoread1.signal();
		oktoread2.signal();
	}
	
	procedure entry type1 read1(){
		if(buffer1.len() == 0) /*buffer vuoto*/
			oktoread1.wait();
		
		buffer1.dequeue;
		oktowrite.signal();
	}
	
	procedure entry type2 read2(){
		if(buffer2.len() == 0) /*buffer vuoto*/
			oktoread2.wait();
		
		buffer2.dequeue;
		oktowrite.signal();
	}
}

Giulia

Esercizio c.2

Esercizio g.1

RoundRobin2cpu.png