Difference between revisions of "ProvaTeorica 2013.02.15"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Stefano 92 (talk | contribs)  (Created page with "Esercizio 1  <syntaxhighlight lang="C"> /* Esercizio c.1: (a) Scrivere un monitor dualwriter che realizzi un doppio buffer limitato (ogni buffer ha ampiezza BUFSIZE) che conse...") | |||
| Line 47: | Line 47: | ||
| </syntaxhighlight> | </syntaxhighlight> | ||
| -stefano92 | -stefano92 | ||
| + | |||
| + | <h2> Esercizio g.1 </h2> | ||
| + | [[File:Espag.jpg]] | ||
Revision as of 19:41, 29 April 2014
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
