<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Stefano+92</id>
	<title>Sistemi Operativi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Stefano+92"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php/Special:Contributions/Stefano_92"/>
	<updated>2026-04-27T04:59:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=732</id>
		<title>ProvaTeorica 2013.02.15</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=732"/>
		<updated>2014-05-15T15:58:04Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2013.02.15.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio c.1: (a) Scrivere un monitor dualwriter che realizzi un doppio buffer limitato (ogni buffer ha ampiezza&lt;br /&gt;
BUFSIZE) che consenta a uno scrittore di scrivere contemporaneamente due elementi che andranno rispettivamente&lt;br /&gt;
nel primo e nel secondo buffer. Le letture :&lt;br /&gt;
 procedure entry void write(type1 e1, type2 e2);&lt;br /&gt;
 procedure entry type1 read1();&lt;br /&gt;
 procedure entry type2 read2();&lt;br /&gt;
La funzione write deve attendere che ci sia spazio in entrambi i buffer. &lt;br /&gt;
La funzione read attende che vi sia almeno un elemento nel buffer indicato&lt;br /&gt;
*/&lt;br /&gt;
monitor dualwriter&lt;br /&gt;
{&lt;br /&gt;
	type1* buffer1;&lt;br /&gt;
	type2* buffer2;&lt;br /&gt;
	condition oktowrite,oktoread1, oktoread2&lt;br /&gt;
	procedure entry void write (type1 e1, type2 e2)&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(type1)&amp;gt;=BUFSIZE || sizeof(type2)&amp;gt;=BUFSIZE)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		buffer1.push(e1);&lt;br /&gt;
		buffer2.push(e2);&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer1)==0)&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		buffer1.pop();&lt;br /&gt;
		if (sizeof(buffer2)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer2)==0)&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		buffer2.pop();&lt;br /&gt;
		if (sizeof(buffer1)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor dualwriter{&lt;br /&gt;
	queue buffer1;&lt;br /&gt;
	queue buffer2;&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktoread1;&lt;br /&gt;
	condition oktoread2;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(type1 e1, type2 e2){&lt;br /&gt;
		if((buffer1.len() == BUFSIZE) || (buffer2.len() == BUFSIZE)) /*se uno dei due buffer è pieno non puoi inserire*/&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.enqueue(e1);&lt;br /&gt;
		buffer2.enqueue(e2);&lt;br /&gt;
		&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1(){&lt;br /&gt;
		if(buffer1.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2(){&lt;br /&gt;
		if(buffer2.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer2.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Giulia&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio c.2 &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// foo(x,y) &amp;lt;x=2+y , y=2+x&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int g = 0;&lt;br /&gt;
&lt;br /&gt;
csenter:&lt;br /&gt;
&lt;br /&gt;
          do&lt;br /&gt;
               int l;&lt;br /&gt;
               foo(l, g);&lt;br /&gt;
          while(l!=2)&lt;br /&gt;
&lt;br /&gt;
csexit:&lt;br /&gt;
&lt;br /&gt;
g = 0;&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// bar (z,t) &amp;lt;z= z xor t, t= t xor z, z = z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
z   t   z   t   z&lt;br /&gt;
0   0   0   0   0&lt;br /&gt;
0   1   1   0   1&lt;br /&gt;
1   0   1   1   0&lt;br /&gt;
1   1   0   1   1&lt;br /&gt;
&lt;br /&gt;
void Swap(bool z, bool t){&lt;br /&gt;
      bool tmp;&lt;br /&gt;
         z=t;&lt;br /&gt;
         t=tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio g.1 &amp;lt;/h2&amp;gt;&lt;br /&gt;
[[File:RoundRobin2cpu.png]]&lt;br /&gt;
&lt;br /&gt;
                                                                            &lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|TEMPO&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|11&lt;br /&gt;
|12&lt;br /&gt;
|13&lt;br /&gt;
|14&lt;br /&gt;
|15&lt;br /&gt;
|16&lt;br /&gt;
|17&lt;br /&gt;
|18&lt;br /&gt;
|19&lt;br /&gt;
|20&lt;br /&gt;
|21&lt;br /&gt;
|22&lt;br /&gt;
|23&lt;br /&gt;
|24&lt;br /&gt;
|25&lt;br /&gt;
|-&lt;br /&gt;
|CPU 1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P4&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|-&lt;br /&gt;
|CPU 2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|I/O&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
Domanda: una soluzione del genere sarebbe corretta?&lt;br /&gt;
-Stefano 92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=731</id>
		<title>ProvaTeorica 2013.02.15</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=731"/>
		<updated>2014-05-15T15:57:35Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2013.02.15.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio c.1: (a) Scrivere un monitor dualwriter che realizzi un doppio buffer limitato (ogni buffer ha ampiezza&lt;br /&gt;
BUFSIZE) che consenta a uno scrittore di scrivere contemporaneamente due elementi che andranno rispettivamente&lt;br /&gt;
nel primo e nel secondo buffer. Le letture :&lt;br /&gt;
 procedure entry void write(type1 e1, type2 e2);&lt;br /&gt;
 procedure entry type1 read1();&lt;br /&gt;
 procedure entry type2 read2();&lt;br /&gt;
La funzione write deve attendere che ci sia spazio in entrambi i buffer. &lt;br /&gt;
La funzione read attende che vi sia almeno un elemento nel buffer indicato&lt;br /&gt;
*/&lt;br /&gt;
monitor dualwriter&lt;br /&gt;
{&lt;br /&gt;
	type1* buffer1;&lt;br /&gt;
	type2* buffer2;&lt;br /&gt;
	condition oktowrite,oktoread1, oktoread2&lt;br /&gt;
	procedure entry void write (type1 e1, type2 e2)&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(type1)&amp;gt;=BUFSIZE || sizeof(type2)&amp;gt;=BUFSIZE)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		buffer1.push(e1);&lt;br /&gt;
		buffer2.push(e2);&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer1)==0)&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		buffer1.pop();&lt;br /&gt;
		if (sizeof(buffer2)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer2)==0)&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		buffer2.pop();&lt;br /&gt;
		if (sizeof(buffer1)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor dualwriter{&lt;br /&gt;
	queue buffer1;&lt;br /&gt;
	queue buffer2;&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktoread1;&lt;br /&gt;
	condition oktoread2;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(type1 e1, type2 e2){&lt;br /&gt;
		if((buffer1.len() == BUFSIZE) || (buffer2.len() == BUFSIZE)) /*se uno dei due buffer è pieno non puoi inserire*/&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.enqueue(e1);&lt;br /&gt;
		buffer2.enqueue(e2);&lt;br /&gt;
		&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1(){&lt;br /&gt;
		if(buffer1.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2(){&lt;br /&gt;
		if(buffer2.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer2.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Giulia&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio c.2 &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// foo(x,y) &amp;lt;x=2+y , y=2+x&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int g = 0;&lt;br /&gt;
&lt;br /&gt;
csenter:&lt;br /&gt;
&lt;br /&gt;
          do&lt;br /&gt;
               int l;&lt;br /&gt;
               foo(l, g);&lt;br /&gt;
          while(l!=2)&lt;br /&gt;
&lt;br /&gt;
csexit:&lt;br /&gt;
&lt;br /&gt;
g = 0;&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// bar (z,t) &amp;lt;z= z xor t, t= t xor z, z = z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
z   t   z   t   z&lt;br /&gt;
0   0   0   0   0&lt;br /&gt;
0   1   1   0   1&lt;br /&gt;
1   0   1   1   0&lt;br /&gt;
1   1   0   1   1&lt;br /&gt;
&lt;br /&gt;
void Swap(bool z, bool t){&lt;br /&gt;
      bool tmp;&lt;br /&gt;
         z=t;&lt;br /&gt;
         t=tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio g.1 &amp;lt;/h2&amp;gt;&lt;br /&gt;
[[File:RoundRobin2cpu.png]]&lt;br /&gt;
&lt;br /&gt;
                                                                            &lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|TEMPO&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|11&lt;br /&gt;
|12&lt;br /&gt;
|13&lt;br /&gt;
|14&lt;br /&gt;
|15&lt;br /&gt;
|16&lt;br /&gt;
|17&lt;br /&gt;
|18&lt;br /&gt;
|19&lt;br /&gt;
|20&lt;br /&gt;
|21&lt;br /&gt;
|22&lt;br /&gt;
|23&lt;br /&gt;
|24&lt;br /&gt;
|25&lt;br /&gt;
|CPU 1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P4&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|-&lt;br /&gt;
|CPU 2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|I/O&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
Domanda: una soluzione del genere sarebbe corretta?&lt;br /&gt;
-Stefano 92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=730</id>
		<title>ProvaTeorica 2013.02.15</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=730"/>
		<updated>2014-05-15T15:56:46Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2013.02.15.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio c.1: (a) Scrivere un monitor dualwriter che realizzi un doppio buffer limitato (ogni buffer ha ampiezza&lt;br /&gt;
BUFSIZE) che consenta a uno scrittore di scrivere contemporaneamente due elementi che andranno rispettivamente&lt;br /&gt;
nel primo e nel secondo buffer. Le letture :&lt;br /&gt;
 procedure entry void write(type1 e1, type2 e2);&lt;br /&gt;
 procedure entry type1 read1();&lt;br /&gt;
 procedure entry type2 read2();&lt;br /&gt;
La funzione write deve attendere che ci sia spazio in entrambi i buffer. &lt;br /&gt;
La funzione read attende che vi sia almeno un elemento nel buffer indicato&lt;br /&gt;
*/&lt;br /&gt;
monitor dualwriter&lt;br /&gt;
{&lt;br /&gt;
	type1* buffer1;&lt;br /&gt;
	type2* buffer2;&lt;br /&gt;
	condition oktowrite,oktoread1, oktoread2&lt;br /&gt;
	procedure entry void write (type1 e1, type2 e2)&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(type1)&amp;gt;=BUFSIZE || sizeof(type2)&amp;gt;=BUFSIZE)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		buffer1.push(e1);&lt;br /&gt;
		buffer2.push(e2);&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer1)==0)&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		buffer1.pop();&lt;br /&gt;
		if (sizeof(buffer2)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer2)==0)&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		buffer2.pop();&lt;br /&gt;
		if (sizeof(buffer1)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor dualwriter{&lt;br /&gt;
	queue buffer1;&lt;br /&gt;
	queue buffer2;&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktoread1;&lt;br /&gt;
	condition oktoread2;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(type1 e1, type2 e2){&lt;br /&gt;
		if((buffer1.len() == BUFSIZE) || (buffer2.len() == BUFSIZE)) /*se uno dei due buffer è pieno non puoi inserire*/&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.enqueue(e1);&lt;br /&gt;
		buffer2.enqueue(e2);&lt;br /&gt;
		&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1(){&lt;br /&gt;
		if(buffer1.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2(){&lt;br /&gt;
		if(buffer2.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer2.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Giulia&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio c.2 &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// foo(x,y) &amp;lt;x=2+y , y=2+x&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int g = 0;&lt;br /&gt;
&lt;br /&gt;
csenter:&lt;br /&gt;
&lt;br /&gt;
          do&lt;br /&gt;
               int l;&lt;br /&gt;
               foo(l, g);&lt;br /&gt;
          while(l!=2)&lt;br /&gt;
&lt;br /&gt;
csexit:&lt;br /&gt;
&lt;br /&gt;
g = 0;&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// bar (z,t) &amp;lt;z= z xor t, t= t xor z, z = z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
z   t   z   t   z&lt;br /&gt;
0   0   0   0   0&lt;br /&gt;
0   1   1   0   1&lt;br /&gt;
1   0   1   1   0&lt;br /&gt;
1   1   0   1   1&lt;br /&gt;
&lt;br /&gt;
void Swap(bool z, bool t){&lt;br /&gt;
      bool tmp;&lt;br /&gt;
         z=t;&lt;br /&gt;
         t=tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio g.1 &amp;lt;/h2&amp;gt;&lt;br /&gt;
[[File:RoundRobin2cpu.png]]&lt;br /&gt;
&lt;br /&gt;
                                                                            &lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|TEMPO&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|11&lt;br /&gt;
|12&lt;br /&gt;
|13&lt;br /&gt;
|14&lt;br /&gt;
|15&lt;br /&gt;
|16&lt;br /&gt;
|17&lt;br /&gt;
|18&lt;br /&gt;
|19&lt;br /&gt;
|20&lt;br /&gt;
|21&lt;br /&gt;
|22&lt;br /&gt;
|23&lt;br /&gt;
|24&lt;br /&gt;
|-&lt;br /&gt;
|CPU 1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P4&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|-&lt;br /&gt;
|CPU 2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|I/O&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
Domanda: una soluzione del genere sarebbe corretta?&lt;br /&gt;
-Stefano 92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=729</id>
		<title>ProvaTeorica 2013.02.15</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.02.15&amp;diff=729"/>
		<updated>2014-05-15T15:55:47Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2013.02.15.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio c.1: (a) Scrivere un monitor dualwriter che realizzi un doppio buffer limitato (ogni buffer ha ampiezza&lt;br /&gt;
BUFSIZE) che consenta a uno scrittore di scrivere contemporaneamente due elementi che andranno rispettivamente&lt;br /&gt;
nel primo e nel secondo buffer. Le letture :&lt;br /&gt;
 procedure entry void write(type1 e1, type2 e2);&lt;br /&gt;
 procedure entry type1 read1();&lt;br /&gt;
 procedure entry type2 read2();&lt;br /&gt;
La funzione write deve attendere che ci sia spazio in entrambi i buffer. &lt;br /&gt;
La funzione read attende che vi sia almeno un elemento nel buffer indicato&lt;br /&gt;
*/&lt;br /&gt;
monitor dualwriter&lt;br /&gt;
{&lt;br /&gt;
	type1* buffer1;&lt;br /&gt;
	type2* buffer2;&lt;br /&gt;
	condition oktowrite,oktoread1, oktoread2&lt;br /&gt;
	procedure entry void write (type1 e1, type2 e2)&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(type1)&amp;gt;=BUFSIZE || sizeof(type2)&amp;gt;=BUFSIZE)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		buffer1.push(e1);&lt;br /&gt;
		buffer2.push(e2);&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer1)==0)&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		buffer1.pop();&lt;br /&gt;
		if (sizeof(buffer2)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2()&lt;br /&gt;
	{&lt;br /&gt;
		if (sizeof(buffer2)==0)&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		buffer2.pop();&lt;br /&gt;
		if (sizeof(buffer1)&amp;lt;BUFSIZE)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor dualwriter{&lt;br /&gt;
	queue buffer1;&lt;br /&gt;
	queue buffer2;&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktoread1;&lt;br /&gt;
	condition oktoread2;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(type1 e1, type2 e2){&lt;br /&gt;
		if((buffer1.len() == BUFSIZE) || (buffer2.len() == BUFSIZE)) /*se uno dei due buffer è pieno non puoi inserire*/&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.enqueue(e1);&lt;br /&gt;
		buffer2.enqueue(e2);&lt;br /&gt;
		&lt;br /&gt;
		oktoread1.signal();&lt;br /&gt;
		oktoread2.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type1 read1(){&lt;br /&gt;
		if(buffer1.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread1.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer1.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry type2 read2(){&lt;br /&gt;
		if(buffer2.len() == 0) /*buffer vuoto*/&lt;br /&gt;
			oktoread2.wait();&lt;br /&gt;
		&lt;br /&gt;
		buffer2.dequeue;&lt;br /&gt;
		oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Giulia&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio c.2 &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// foo(x,y) &amp;lt;x=2+y , y=2+x&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int g = 0;&lt;br /&gt;
&lt;br /&gt;
csenter:&lt;br /&gt;
&lt;br /&gt;
          do&lt;br /&gt;
               int l;&lt;br /&gt;
               foo(l, g);&lt;br /&gt;
          while(l!=2)&lt;br /&gt;
&lt;br /&gt;
csexit:&lt;br /&gt;
&lt;br /&gt;
g = 0;&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// bar (z,t) &amp;lt;z= z xor t, t= t xor z, z = z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
z   t   z   t   z&lt;br /&gt;
0   0   0   0   0&lt;br /&gt;
0   1   1   0   1&lt;br /&gt;
1   0   1   1   0&lt;br /&gt;
1   1   0   1   1&lt;br /&gt;
&lt;br /&gt;
void Swap(bool z, bool t){&lt;br /&gt;
      bool tmp;&lt;br /&gt;
         z=t;&lt;br /&gt;
         t=tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio g.1 &amp;lt;/h2&amp;gt;&lt;br /&gt;
[[File:RoundRobin2cpu.png]]&lt;br /&gt;
&lt;br /&gt;
                                                                            &lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|TEMPO&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|11&lt;br /&gt;
|12&lt;br /&gt;
|13&lt;br /&gt;
|14&lt;br /&gt;
|15&lt;br /&gt;
|16&lt;br /&gt;
|17&lt;br /&gt;
|18&lt;br /&gt;
|19&lt;br /&gt;
|20&lt;br /&gt;
|21&lt;br /&gt;
|22&lt;br /&gt;
|23&lt;br /&gt;
|24&lt;br /&gt;
|-&lt;br /&gt;
|CPU 1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P4&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P4&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|CPU 2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|I/O&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P2&lt;br /&gt;
|P3&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P1&lt;br /&gt;
|P4&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|&amp;lt;br&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
Domanda: una soluzione del genere sarebbe corretta?&lt;br /&gt;
-Stefano 92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=710</id>
		<title>ProvaTeoria 2011.01.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=710"/>
		<updated>2014-05-12T14:29:24Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2011-01-17.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Scrivere un monitor reqq che gestisca una coda di richieste.&lt;br /&gt;
I richiedenti chiamano la funzione che ha la seguente signature:&lt;br /&gt;
answer_t reqq.query(request_t request);&lt;br /&gt;
Query deve fermare il processo richiedente fino a completamento della richiesta da parte di un gestore. Il valore di ritorno &lt;br /&gt;
e' la risposta del gestore.&lt;br /&gt;
Ci sono N gestori che si comportano come segue:&lt;br /&gt;
multiq_handler: process[i, i=0,..,N-1] {&lt;br /&gt;
	request_t req;&lt;br /&gt;
	int type;&lt;br /&gt;
	while (1) {&lt;br /&gt;
		 req=reqq.getquery(i);&lt;br /&gt;
		 reqq.reply(i,handle(req));&lt;br /&gt;
 	}&lt;br /&gt;
}&lt;br /&gt;
Le richieste vengono assegnate ai gestori disponibili o accodate se sono tutti impegnati. Quando un gestore termina la &lt;br /&gt;
gestione (funzione handle, che non implementare!) invia il risultato tramite la reply. Il valore passato alla reply deve &lt;br /&gt;
essere restituito al richiedente come valore di ritorno della funzione query. Se non vi sono richieste disponibili i gestori si &lt;br /&gt;
fermano attendendo nuove richieste.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La mia soluzione si basa su una struttura reqEntry contenente un campo per la domanda, uno per la risposta, una condizione oktoexit e un intero per il gestore.&lt;br /&gt;
Quando arriva un richiedente inserisce una struttura con una domanda e con i campi risposta e gestore vuoti.&lt;br /&gt;
Quando un gestore si occupa di una domanda setta l'opportuno campo gestore al suo indice e, al termine della routine handle(), inserisce la sua risposta nell'opportuno&lt;br /&gt;
campo della struct risvegliando il richiedente*/&lt;br /&gt;
&lt;br /&gt;
struct reqEntry&lt;br /&gt;
{&lt;br /&gt;
	request_t req;&lt;br /&gt;
	condition oktoexit;&lt;br /&gt;
	answer_t reply=NULL;&lt;br /&gt;
	int handler=VOID; //VOID è un valore speciale avente valore diverso dagli indici dei gestori&lt;br /&gt;
}&lt;br /&gt;
monitor reqq&lt;br /&gt;
{&lt;br /&gt;
	reqEntry* rq=Queue(); /*coda di reqEntry*/&lt;br /&gt;
	condition oktohandle; /*per i gestori*/&lt;br /&gt;
	answer_t procedure entry query(request_t request)&lt;br /&gt;
	{&lt;br /&gt;
		rq.insert(request); &lt;br /&gt;
		rp=rq.searchByReq(request);&lt;br /&gt;
		oktohandle.signal(); /*cerco se esiste un gestore in attesa per la mia richiesta*/&lt;br /&gt;
		rp-&amp;gt;oktoexit.wait();&lt;br /&gt;
		risp=rp-&amp;gt;reply; &lt;br /&gt;
		remove(rp); /*recupero la risposta e rimuovo la struct dalla coda*/&lt;br /&gt;
		return risp;	&lt;br /&gt;
	}&lt;br /&gt;
	request_t procedure entry  getquery(int index)&lt;br /&gt;
	{&lt;br /&gt;
		if isEmptyFree(rq) /*isEmptyFree ritorna 1 se non ci sono struct libere (cioè con handler VOID) nella coda di reqEntry*/&lt;br /&gt;
		{&lt;br /&gt;
			oktohandle.wait();&lt;br /&gt;
		}&lt;br /&gt;
		rp=rq.searchFree(); /*restituisce un elemento della coda di reqEntry avente handler VOID*/&lt;br /&gt;
		rp-&amp;gt;handler=index; &lt;br /&gt;
		return rp;&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry reply(int index, answer_t rep)&lt;br /&gt;
	{&lt;br /&gt;
		rp=rq.searchByHandler(index); /*cerca nella lista la struct avente handler uguale al mio indice*/&lt;br /&gt;
		rp-&amp;gt;reply=rep;&lt;br /&gt;
		rp-&amp;gt;oktoexit.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
struct sendINFO&lt;br /&gt;
{&lt;br /&gt;
	pid_t receiver;&lt;br /&gt;
	int nmsg;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sendINFO* listINFO=List(); //ogni processo ha un database di strutture sendINFO per sapere quanti messaggi di ogni destinatario&lt;br /&gt;
						   //risultano ancora non recapitati&lt;br /&gt;
&lt;br /&gt;
T* database=List(); //ogni processo ha un database di messaggi &lt;br /&gt;
&lt;br /&gt;
int iasend(pid_t destination, T message)&lt;br /&gt;
{&lt;br /&gt;
	T tmpMSG;&lt;br /&gt;
	sendINFO tmpINFO;&lt;br /&gt;
	asend(destination,message);	&lt;br /&gt;
	if ((tmpINFO=listINFO.search(destination))==NULL) //se questo destinatario non ha ancora un'entry nella lista, lo inserisco&lt;br /&gt;
		{&lt;br /&gt;
			list.insert(destination,0);&lt;br /&gt;
			tmpINFO=listINFO.search(destination);&lt;br /&gt;
		}&lt;br /&gt;
	tmpINFO.nmsg++; &lt;br /&gt;
	&lt;br /&gt;
	/*SCORRIMENTO BUFFER DI MESSAGGI E AGGIORNAMENTO LISTA*/&lt;br /&gt;
	asend(getpid(),&amp;quot;BOT&amp;quot;); &lt;br /&gt;
	while((tmpMSG=arecv(*))!=&amp;quot;BOT&amp;quot;)&lt;br /&gt;
	{&lt;br /&gt;
		if (tmpMSG==&amp;quot;OK&amp;quot;)&lt;br /&gt;
		{&lt;br /&gt;
			tmpINFO=listINFO.search(tmpMSG.sender);&lt;br /&gt;
			tmpINFO.nmsg--;&lt;br /&gt;
			if (nmsg==0)&lt;br /&gt;
				listINFO.remove(tmpINFO);&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
			db.add(tmpMSG);&lt;br /&gt;
	}&lt;br /&gt;
	tmpINFO=search(destination);&lt;br /&gt;
	if(tmpINFO!=NULL)&lt;br /&gt;
		return tmpINFO.nmsg;&lt;br /&gt;
	else&lt;br /&gt;
		return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
T iareceive(pid_t sender)&lt;br /&gt;
{&lt;br /&gt;
	T ris;&lt;br /&gt;
	ris=db.search(sender);&lt;br /&gt;
	if (ris==NULL)&lt;br /&gt;
		ris=arecv(sender);&lt;br /&gt;
	asend(sender,&amp;quot;OK&amp;quot;);&lt;br /&gt;
	return ris;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=708</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=708"/>
		<updated>2014-05-12T11:41:02Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List() /*lista di condizioni, una per ogni processo arrivato*/&lt;br /&gt;
	int* procstack=Stack(); /*stack di processi per l'uscita LIFO*/&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){ /*cioè se il processo non è in cima allo stack*/&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait(); /*aggiungo il mio p_id alla lista di condizioni e mi metto in wait*/&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione&lt;br /&gt;
&lt;br /&gt;
==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
pid index[N] /*index contiene gli id dei vari server*/&lt;br /&gt;
&lt;br /&gt;
process server[0]&lt;br /&gt;
{&lt;br /&gt;
	while(1)&lt;br /&gt;
	{&lt;br /&gt;
		tmp msg=arecv(*);&lt;br /&gt;
		for (i=1;i&amp;lt;N;i++)&lt;br /&gt;
			asend(index[i],tmp);&lt;br /&gt;
		print(tmp);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
process server[1...N-1]&lt;br /&gt;
{&lt;br /&gt;
	while(1)&lt;br /&gt;
	{&lt;br /&gt;
		msg tmp =arecv(*)&lt;br /&gt;
		if (tmp.sender==index[0])&lt;br /&gt;
			print(tmp);&lt;br /&gt;
		else&lt;br /&gt;
			asend(index[0],tmp);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=692</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=692"/>
		<updated>2014-05-07T09:02:19Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List() /*lista di condizioni, una per ogni processo arrivato*/&lt;br /&gt;
	int* procstack=Stack(); /*stack di processi per l'uscita LIFO*/&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){ /*cioè se il processo non è in cima allo stack*/&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait(); /*aggiungo il mio p_id alla lista di condizioni e mi metto in wait*/&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione&lt;br /&gt;
&lt;br /&gt;
==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
pid index[N] /*index contiene gli id dei vari server*/&lt;br /&gt;
&lt;br /&gt;
process server[0]&lt;br /&gt;
{&lt;br /&gt;
	while(1)&lt;br /&gt;
	{&lt;br /&gt;
		tmp msg=arecv(*);&lt;br /&gt;
		for (i=1;i&amp;lt;N;i++)&lt;br /&gt;
			asend(index[i],msg);&lt;br /&gt;
		print(msg);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
process server[1...N-1]&lt;br /&gt;
{&lt;br /&gt;
	while(1)&lt;br /&gt;
	{&lt;br /&gt;
		tmp msg=arecv(*)&lt;br /&gt;
		if (tmp.sender==index[0])&lt;br /&gt;
			print(msg);&lt;br /&gt;
		else&lt;br /&gt;
			asend(index[0],msg);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=691</id>
		<title>ProvaTeoria 2011.07.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=691"/>
		<updated>2014-05-07T08:55:28Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//siano dati tre processi &amp;quot;stampa&amp;quot; come segue:&lt;br /&gt;
//stampa(x):(x=A,T,R) process&lt;br /&gt;
//while (true) {&lt;br /&gt;
// synchro(x);&lt;br /&gt;
// print(x);&lt;br /&gt;
//}&lt;br /&gt;
//scrivere la fuzione synchro() facendo uso di semafori che consenta di avere in output una sequenza infinita&lt;br /&gt;
//di TARATATA (i.e. TARATATATARATATATARATATATARATATATARATATA......)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La soluzione prevede l'utilizzo di 3 semafori, uno per ogni lettera (T,A,R). E' presente anche una variabile buflen contenente&lt;br /&gt;
 la lunghezza della stringa stampata fino ad ora.&lt;br /&gt;
   L'idea si basa sull'utilizzo di una funzione mutex_print() che, a seconda dell'output generato, libera l'opportuno semaforo.&lt;br /&gt;
 Le risorse dei semafori vengono poi richieste dai processi.*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*definizione variabili di supporto e #define*/&lt;br /&gt;
&lt;br /&gt;
#DEFINE T 0&lt;br /&gt;
#DEFINE R 1&lt;br /&gt;
#DEFINE A 2&lt;br /&gt;
int buflen=0;&lt;br /&gt;
&lt;br /&gt;
/*definizione dei semafori*/&lt;br /&gt;
int sem[3];&lt;br /&gt;
sem[T]=1;&lt;br /&gt;
sem[R]=0&lt;br /&gt;
sem[A]=0&lt;br /&gt;
&lt;br /&gt;
/*funzione di supporto: controlla se è arrivato il momento di stampare una R*/&lt;br /&gt;
int checkR(int x)&lt;br /&gt;
{&lt;br /&gt;
  if((x-2)%8==0)&lt;br /&gt;
     return 1;&lt;br /&gt;
  else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void mutex_print()&lt;br /&gt;
{&lt;br /&gt;
if (buflen==0) return;&lt;br /&gt;
else if (buflen%2!=0)&lt;br /&gt;
  v(sem[A]);&lt;br /&gt;
else if (checkR(buflen))&lt;br /&gt;
  v(sem[R]);&lt;br /&gt;
else v(sem[T]);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
void synchro(int x)&lt;br /&gt;
{&lt;br /&gt;
mutex();&lt;br /&gt;
p(sem[x]);&lt;br /&gt;
buflen++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 3: Dato un servizio di message passing asincrono (NON completamente asincrono) e senza fare uso di un &lt;br /&gt;
server implementare un servizio di message passing sincrono LIFO. (cioe' dati asend/arecv, implementare lssend &lt;br /&gt;
lsrecv)&lt;br /&gt;
I messaggi possono essere di grandi dimensioni, si chiede quindi che l'implementazione non crei una coda con tutti i &lt;br /&gt;
messaggi in attesa di essere ricevuti.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
pid* database=Stack();&lt;br /&gt;
&lt;br /&gt;
void lssend(int dest,message m)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	asend(dest,&amp;quot;#&amp;quot;);&lt;br /&gt;
	tmp=arecv(dest);&lt;br /&gt;
	asend(dest,msg)&lt;br /&gt;
	arecv(dest);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
		&lt;br /&gt;
message lsrecv(pid sender)&lt;br /&gt;
{&lt;br /&gt;
    message tmp;&lt;br /&gt;
    pid_t replier;&lt;br /&gt;
    asend(&amp;quot;BOT&amp;quot;,getpid());&lt;br /&gt;
    while(tmp=arecv(*)!=BOT)&lt;br /&gt;
    {&lt;br /&gt;
	database.push(tmp.sender);&lt;br /&gt;
    }&lt;br /&gt;
    replier=database.pop(sender);&lt;br /&gt;
    if (replier==NULL)&lt;br /&gt;
	{&lt;br /&gt;
	    tmp=arecv(sender);&lt;br /&gt;
	    replier=tmp.sender;&lt;br /&gt;
	}&lt;br /&gt;
    asend(replier,&amp;quot;OK&amp;quot;);&lt;br /&gt;
    tmp=arecv(replier);&lt;br /&gt;
    asend(replier,&amp;quot;END&amp;quot;);&lt;br /&gt;
    return tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=690</id>
		<title>ProvaTeoria 2011.07.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=690"/>
		<updated>2014-05-07T08:55:08Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//siano dati tre processi &amp;quot;stampa&amp;quot; come segue:&lt;br /&gt;
//stampa(x):(x=A,T,R) process&lt;br /&gt;
//while (true) {&lt;br /&gt;
// synchro(x);&lt;br /&gt;
// print(x);&lt;br /&gt;
//}&lt;br /&gt;
//scrivere la fuzione synchro() facendo uso di semafori che consenta di avere in output una sequenza infinita&lt;br /&gt;
//di TARATATA (i.e. TARATATATARATATATARATATATARATATATARATATA......)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La soluzione prevede l'utilizzo di 3 semafori, uno per ogni lettera (T,A,R). E' presente anche una variabile buflen contenente&lt;br /&gt;
 la lunghezza della stringa stampata fino ad ora.&lt;br /&gt;
   L'idea si basa sull'utilizzo di una funzione mutex_print() che, a seconda dell'output generato, libera l'opportuno semaforo.&lt;br /&gt;
 Le risorse dei semafori vengono poi richieste dai processi.*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*definizione variabili di supporto e #define*/&lt;br /&gt;
&lt;br /&gt;
#DEFINE T 0&lt;br /&gt;
#DEFINE R 1&lt;br /&gt;
#DEFINE A 2&lt;br /&gt;
int buflen=0;&lt;br /&gt;
&lt;br /&gt;
/*definizione dei semafori*/&lt;br /&gt;
int sem[3];&lt;br /&gt;
sem[T]=1;&lt;br /&gt;
sem[R]=0&lt;br /&gt;
sem[A]=0&lt;br /&gt;
&lt;br /&gt;
/*funzione di supporto: controlla se è arrivato il momento di stampare una R*/&lt;br /&gt;
int checkR(int x)&lt;br /&gt;
{&lt;br /&gt;
  if((x-2)%8==0)&lt;br /&gt;
     return 1;&lt;br /&gt;
  else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void mutex_print()&lt;br /&gt;
{&lt;br /&gt;
if (buflen==0) return;&lt;br /&gt;
else if (buflen%2!=0)&lt;br /&gt;
  v(sem[A]);&lt;br /&gt;
else if (checkR(buflen))&lt;br /&gt;
  v(sem[R]);&lt;br /&gt;
else v(sem[T]);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
void synchro(int x)&lt;br /&gt;
{&lt;br /&gt;
mutex();&lt;br /&gt;
p(sem[x]);&lt;br /&gt;
buflen++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 3: Dato un servizio di message passing asincrono (NON completamente asincrono) e senza fare uso di un &lt;br /&gt;
server implementare un servizio di message passing sincrono LIFO. (cioe' dati asend/arecv, implementare lssend &lt;br /&gt;
lsrecv)&lt;br /&gt;
I messaggi possono essere di grandi dimensioni, si chiede quindi che l'implementazione non crei una coda con tutti i &lt;br /&gt;
messaggi in attesa di essere ricevuti.&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
pid* database=Stack();&lt;br /&gt;
&lt;br /&gt;
void lssend(int dest,message m)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	asend(dest,&amp;quot;#&amp;quot;);&lt;br /&gt;
	tmp=arecv(dest);&lt;br /&gt;
	asend(dest,msg)&lt;br /&gt;
	arecv(dest);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
		&lt;br /&gt;
message lsrecv(pid sender)&lt;br /&gt;
{&lt;br /&gt;
    message tmp;&lt;br /&gt;
    pid_t replier;&lt;br /&gt;
    asend(&amp;quot;BOT&amp;quot;,getpid());&lt;br /&gt;
    while(tmp=arecv(*)!=BOT)&lt;br /&gt;
    {&lt;br /&gt;
	database.push(tmp.sender);&lt;br /&gt;
    }&lt;br /&gt;
    replier=database.pop(sender);&lt;br /&gt;
    if (replier==NULL)&lt;br /&gt;
	{&lt;br /&gt;
	    tmp=arecv(sender);&lt;br /&gt;
	    replier=tmp.sender;&lt;br /&gt;
	}&lt;br /&gt;
    asend(replier,&amp;quot;OK&amp;quot;);&lt;br /&gt;
    tmp=arecv(replier);&lt;br /&gt;
    asend(replier,&amp;quot;END&amp;quot;);&lt;br /&gt;
    return tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=689</id>
		<title>ProvaTeoria 2011.07.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=689"/>
		<updated>2014-05-07T08:54:12Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//siano dati tre processi &amp;quot;stampa&amp;quot; come segue:&lt;br /&gt;
//stampa(x):(x=A,T,R) process&lt;br /&gt;
//while (true) {&lt;br /&gt;
// synchro(x);&lt;br /&gt;
// print(x);&lt;br /&gt;
//}&lt;br /&gt;
//scrivere la fuzione synchro() facendo uso di semafori che consenta di avere in output una sequenza infinita&lt;br /&gt;
//di TARATATA (i.e. TARATATATARATATATARATATATARATATATARATATA......)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La soluzione prevede l'utilizzo di 3 semafori, uno per ogni lettera (T,A,R). E' presente anche una variabile buflen contenente&lt;br /&gt;
 la lunghezza della stringa stampata fino ad ora.&lt;br /&gt;
   L'idea si basa sull'utilizzo di una funzione mutex_print() che, a seconda dell'output generato, libera l'opportuno semaforo.&lt;br /&gt;
 Le risorse dei semafori vengono poi richieste dai processi.*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*definizione variabili di supporto e #define*/&lt;br /&gt;
&lt;br /&gt;
#DEFINE T 0&lt;br /&gt;
#DEFINE R 1&lt;br /&gt;
#DEFINE A 2&lt;br /&gt;
int buflen=0;&lt;br /&gt;
&lt;br /&gt;
/*definizione dei semafori*/&lt;br /&gt;
int sem[3];&lt;br /&gt;
sem[T]=1;&lt;br /&gt;
sem[R]=0&lt;br /&gt;
sem[A]=0&lt;br /&gt;
&lt;br /&gt;
/*funzione di supporto: controlla se è arrivato il momento di stampare una R*/&lt;br /&gt;
int checkR(int x)&lt;br /&gt;
{&lt;br /&gt;
  if((x-2)%8==0)&lt;br /&gt;
     return 1;&lt;br /&gt;
  else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void mutex_print()&lt;br /&gt;
{&lt;br /&gt;
if (buflen==0) return;&lt;br /&gt;
else if (buflen%2!=0)&lt;br /&gt;
  v(sem[A]);&lt;br /&gt;
else if (checkR(buflen))&lt;br /&gt;
  v(sem[R]);&lt;br /&gt;
else v(sem[T]);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
void synchro(int x)&lt;br /&gt;
{&lt;br /&gt;
mutex();&lt;br /&gt;
p(sem[x]);&lt;br /&gt;
buflen++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 3: Dato un servizio di message passing asincrono (NON completamente asincrono) e senza fare uso di un &lt;br /&gt;
server implementare un servizio di message passing sincrono LIFO. (cioe' dati asend/arecv, implementare lssend &lt;br /&gt;
lsrecv)&lt;br /&gt;
I messaggi possono essere di grandi dimensioni, si chiede quindi che l'implementazione non crei una coda con tutti i &lt;br /&gt;
messaggi in attesa di essere ricevuti.&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
pid* database=Stack();&lt;br /&gt;
&lt;br /&gt;
void lssend(int dest,message m)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	asend(dest,&amp;quot;#&amp;quot;);&lt;br /&gt;
	tmp=arecv(dest);&lt;br /&gt;
	asend(dest,msg)&lt;br /&gt;
	arecv(dest);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
		&lt;br /&gt;
message lsrecv(pid sender)&lt;br /&gt;
{&lt;br /&gt;
    message tmp;&lt;br /&gt;
    pid_t replier;&lt;br /&gt;
    asend(&amp;quot;BOT&amp;quot;,getpid());&lt;br /&gt;
	while(tmp=arecv(*)!=BOT)&lt;br /&gt;
	{&lt;br /&gt;
		database.push(tmp.sender);&lt;br /&gt;
	}&lt;br /&gt;
	replier=database.pop(sender);&lt;br /&gt;
	if (replier==NULL)&lt;br /&gt;
	{&lt;br /&gt;
		tmp=arecv(sender);&lt;br /&gt;
		replier=tmp.sender;&lt;br /&gt;
	}&lt;br /&gt;
		asend(replier,&amp;quot;OK&amp;quot;);&lt;br /&gt;
		tmp=arecv(replier);&lt;br /&gt;
		asend(replier,&amp;quot;END&amp;quot;);&lt;br /&gt;
		return tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=688</id>
		<title>ProvaTeoria 2011.07.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=688"/>
		<updated>2014-05-05T14:03:43Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//siano dati tre processi &amp;quot;stampa&amp;quot; come segue:&lt;br /&gt;
//stampa(x):(x=A,T,R) process&lt;br /&gt;
//while (true) {&lt;br /&gt;
// synchro(x);&lt;br /&gt;
// print(x);&lt;br /&gt;
//}&lt;br /&gt;
//scrivere la fuzione synchro() facendo uso di semafori che consenta di avere in output una sequenza infinita&lt;br /&gt;
//di TARATATA (i.e. TARATATATARATATATARATATATARATATATARATATA......)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La soluzione prevede l'utilizzo di 3 semafori, uno per ogni lettera (T,A,R). E' presente anche una variabile buflen contenente&lt;br /&gt;
 la lunghezza della stringa stampata fino ad ora.&lt;br /&gt;
   L'idea si basa sull'utilizzo di una funzione mutex_print() che, a seconda dell'output generato, libera l'opportuno semaforo.&lt;br /&gt;
 Le risorse dei semafori vengono poi richieste dai processi.*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*definizione variabili di supporto e #define*/&lt;br /&gt;
&lt;br /&gt;
#DEFINE T 0&lt;br /&gt;
#DEFINE R 1&lt;br /&gt;
#DEFINE A 2&lt;br /&gt;
int buflen=0;&lt;br /&gt;
&lt;br /&gt;
/*definizione dei semafori*/&lt;br /&gt;
int sem[3];&lt;br /&gt;
sem[T]=1;&lt;br /&gt;
sem[R]=0&lt;br /&gt;
sem[A]=0&lt;br /&gt;
&lt;br /&gt;
/*funzione di supporto: controlla se è arrivato il momento di stampare una R*/&lt;br /&gt;
int checkR(int x)&lt;br /&gt;
{&lt;br /&gt;
  if((x-2)%8==0)&lt;br /&gt;
     return 1;&lt;br /&gt;
  else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void mutex_print()&lt;br /&gt;
{&lt;br /&gt;
if (buflen==0) return;&lt;br /&gt;
else if (buflen%2!=0)&lt;br /&gt;
  v(sem[A]);&lt;br /&gt;
else if (checkR(buflen))&lt;br /&gt;
  v(sem[R]);&lt;br /&gt;
else v(sem[T]);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
void synchro(int x)&lt;br /&gt;
{&lt;br /&gt;
mutex();&lt;br /&gt;
p(sem[x]);&lt;br /&gt;
buflen++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 3: Dato un servizio di message passing asincrono (NON completamente asincrono) e senza fare uso di un &lt;br /&gt;
server implementare un servizio di message passing sincrono LIFO. (cioe' dati asend/arecv, implementare lssend &lt;br /&gt;
lsrecv)&lt;br /&gt;
I messaggi possono essere di grandi dimensioni, si chiede quindi che l'implementazione non crei una coda con tutti i &lt;br /&gt;
messaggi in attesa di essere ricevuti.&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
pid* database=Queue();&lt;br /&gt;
&lt;br /&gt;
void lssend(int dest,message m)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	asend(dest,&amp;quot;#&amp;quot;);&lt;br /&gt;
		tmp=arecv(dest);&lt;br /&gt;
	asend(dest,msg)&lt;br /&gt;
	arecv(dest);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
message lsrecv(pid sender)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	pid replier; //replier conterrà il p_id del sender da cui ricevere il messaggio&lt;br /&gt;
	if (sender!=*)&lt;br /&gt;
		{&lt;br /&gt;
			arecv(sender);&lt;br /&gt;
			replier=sender; //devo sicuramente ricevere da questo sender &lt;br /&gt;
		}&lt;br /&gt;
	else&lt;br /&gt;
		{&lt;br /&gt;
			asend(&amp;quot;BOT&amp;quot;,getpid()); //per la lettura del buffer di messaggi&lt;br /&gt;
			tmp=arecv(*);&lt;br /&gt;
			if (tmp==&amp;quot;BOT&amp;quot;)&lt;br /&gt;
			{&lt;br /&gt;
				//coda di messaggi vuota: recupero il primo replier disponibile dal DB&lt;br /&gt;
				replier=db.dequeue();&lt;br /&gt;
				if (replier==NULL)&lt;br /&gt;
				{&lt;br /&gt;
					//coda vuota e DB vuoto: il primo messaggio arrivato è quello da ritornare&lt;br /&gt;
					tmp=arecv(*);&lt;br /&gt;
					replier=tmp.sender;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else do&lt;br /&gt;
			{&lt;br /&gt;
				//cerco l'ultimo messaggio prima di bottom: metto i sender di tutti gli altri messaggi nel DB&lt;br /&gt;
				replier=tmp.sender;&lt;br /&gt;
				tmp=arecv(*);&lt;br /&gt;
				if (tmp!=&amp;quot;BOT&amp;quot;)&lt;br /&gt;
				{&lt;br /&gt;
					db.enqueue(replier);&lt;br /&gt;
					replier=tmp.sender;&lt;br /&gt;
				}	&lt;br /&gt;
			}&lt;br /&gt;
			while (tmp!=&amp;quot;BOT&amp;quot;);&lt;br /&gt;
		//ho trovato il mio replier&lt;br /&gt;
		}&lt;br /&gt;
		asend(replier,&amp;quot;OK&amp;quot;);&lt;br /&gt;
		tmp=arecv(replier);&lt;br /&gt;
		asend(replier,&amp;quot;END&amp;quot;);&lt;br /&gt;
		return tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=687</id>
		<title>ProvaTeoria 2011.07.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=687"/>
		<updated>2014-05-05T14:02:44Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//siano dati tre processi &amp;quot;stampa&amp;quot; come segue:&lt;br /&gt;
//stampa(x):(x=A,T,R) process&lt;br /&gt;
//while (true) {&lt;br /&gt;
// synchro(x);&lt;br /&gt;
// print(x);&lt;br /&gt;
//}&lt;br /&gt;
//scrivere la fuzione synchro() facendo uso di semafori che consenta di avere in output una sequenza infinita&lt;br /&gt;
//di TARATATA (i.e. TARATATATARATATATARATATATARATATATARATATA......)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La soluzione prevede l'utilizzo di 3 semafori, uno per ogni lettera (T,A,R). E' presente anche una variabile buflen contenente&lt;br /&gt;
 la lunghezza della stringa stampata fino ad ora.&lt;br /&gt;
   L'idea si basa sull'utilizzo di una funzione mutex_print() che, a seconda dell'output generato, libera l'opportuno semaforo.&lt;br /&gt;
 Le risorse dei semafori vengono poi richieste dai processi.*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*definizione variabili di supporto e #define*/&lt;br /&gt;
&lt;br /&gt;
#DEFINE T 0&lt;br /&gt;
#DEFINE R 1&lt;br /&gt;
#DEFINE A 2&lt;br /&gt;
int buflen=0;&lt;br /&gt;
&lt;br /&gt;
/*definizione dei semafori*/&lt;br /&gt;
int sem[3];&lt;br /&gt;
sem[T]=1;&lt;br /&gt;
sem[R]=0&lt;br /&gt;
sem[A]=0&lt;br /&gt;
&lt;br /&gt;
/*funzione di supporto: controlla se è arrivato il momento di stampare una R*/&lt;br /&gt;
int checkR(int x)&lt;br /&gt;
{&lt;br /&gt;
  if((x-2)%8==0)&lt;br /&gt;
     return 1;&lt;br /&gt;
  else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void mutex_print()&lt;br /&gt;
{&lt;br /&gt;
if (buflen==0) return;&lt;br /&gt;
else if (buflen%2!=0)&lt;br /&gt;
  v(sem[A]);&lt;br /&gt;
else if (checkR(buflen))&lt;br /&gt;
  v(sem[R]);&lt;br /&gt;
else v(sem[T]);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
void synchro(int x)&lt;br /&gt;
{&lt;br /&gt;
mutex();&lt;br /&gt;
p(sem[x]);&lt;br /&gt;
buflen++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 3: Dato un servizio di message passing asincrono (NON completamente asincrono) e senza fare uso di un &lt;br /&gt;
server implementare un servizio di message passing sincrono LIFO. (cioe' dati asend/arecv, implementare lssend &lt;br /&gt;
lsrecv)&lt;br /&gt;
I messaggi possono essere di grandi dimensioni, si chiede quindi che l'implementazione non crei una coda con tutti i &lt;br /&gt;
messaggi in attesa di essere ricevuti.&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
pid* database=Queue();&lt;br /&gt;
&lt;br /&gt;
void lssend(int dest,message m)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	asend(dest,&amp;quot;#&amp;quot;);&lt;br /&gt;
		tmp=arecv(dest);&lt;br /&gt;
	asend(dest,&amp;quot;OK&amp;quot;)&lt;br /&gt;
	arecv(dest);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
message lsrecv(pid sender)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	pid replier; //replier conterrà il p_id del sender da cui ricevere il messaggio&lt;br /&gt;
	if (sender!=*)&lt;br /&gt;
		{&lt;br /&gt;
			arecv(sender);&lt;br /&gt;
			replier=sender; //devo sicuramente ricevere da questo sender &lt;br /&gt;
		}&lt;br /&gt;
	else&lt;br /&gt;
		{&lt;br /&gt;
			asend(&amp;quot;BOT&amp;quot;,getpid()); //per la lettura del buffer di messaggi&lt;br /&gt;
			tmp=arecv(*);&lt;br /&gt;
			if (tmp==&amp;quot;BOT&amp;quot;)&lt;br /&gt;
			{&lt;br /&gt;
				//coda di messaggi vuota: recupero il primo replier disponibile dal DB&lt;br /&gt;
				replier=db.dequeue();&lt;br /&gt;
				if (replier==NULL)&lt;br /&gt;
				{&lt;br /&gt;
					//coda vuota e DB vuoto: il primo messaggio arrivato è quello da ritornare&lt;br /&gt;
					tmp=arecv(*);&lt;br /&gt;
					replier=tmp.sender;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else do&lt;br /&gt;
			{&lt;br /&gt;
				//cerco l'ultimo messaggio prima di bottom: metto i sender di tutti gli altri messaggi nel DB&lt;br /&gt;
				replier=tmp.sender;&lt;br /&gt;
				tmp=arecv(*);&lt;br /&gt;
				if (tmp!=&amp;quot;BOT&amp;quot;)&lt;br /&gt;
				{&lt;br /&gt;
					db.enqueue(replier);&lt;br /&gt;
					replier=tmp.sender;&lt;br /&gt;
				}	&lt;br /&gt;
			}&lt;br /&gt;
			while (tmp!=&amp;quot;BOT&amp;quot;);&lt;br /&gt;
		//ho trovato il mio replier&lt;br /&gt;
		}&lt;br /&gt;
		asend(replier,&amp;quot;OK&amp;quot;);&lt;br /&gt;
		tmp=arecv(replier);&lt;br /&gt;
		asend(replier,&amp;quot;END&amp;quot;);&lt;br /&gt;
		return tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=686</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=686"/>
		<updated>2014-05-05T13:48:36Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.06.23]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=685</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=685"/>
		<updated>2014-05-05T13:46:56Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.06.23]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=684</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=684"/>
		<updated>2014-05-05T13:21:30Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.06.23]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.06.23&amp;diff=683</id>
		<title>ProvaPratica 2009.06.23</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.06.23&amp;diff=683"/>
		<updated>2014-05-05T13:20:47Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/pratiche/2009.06.23.pdf&amp;lt;/h1&amp;gt;  == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;  /* Esercizio1 (obbligatorio): (15 punti) Scrivere un programm...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/pratiche/2009.06.23.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Esercizio1 (obbligatorio): (15 punti) Scrivere un programma in linguaggio C denominato “scriptexec” che venga &lt;br /&gt;
richiamato con un solo parametro: il nome di un file che contiene un elenco di comandi con i rispettivi parametri, uno per &lt;br /&gt;
riga.&lt;br /&gt;
Le righe che iniziano per '#' sono commenti.&lt;br /&gt;
Il programma esegue uno dopo l'altro i comandi presenti nel file.&lt;br /&gt;
(E' vietato l'uso di chiamate quali system o popen).*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[])&lt;br /&gt;
{&lt;br /&gt;
	if (argc!=2)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Usage: ./scriptexec COMMAND_FILE\n&amp;quot;);&lt;br /&gt;
		return(1);&lt;br /&gt;
	}&lt;br /&gt;
	FILE* fp;&lt;br /&gt;
	char* buf= NULL;&lt;br /&gt;
	int ris=0,ris_fork=0;&lt;br /&gt;
	unsigned long size=0;&lt;br /&gt;
	fp=fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
	if(fp == NULL)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;FILE NON ESISTENTE\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	while ((ris=getline(&amp;amp;buf,&amp;amp;size,fp)!=-1))&lt;br /&gt;
	{&lt;br /&gt;
		if (buf[0]!='#')&lt;br /&gt;
		{&lt;br /&gt;
			ris_fork= fork();&lt;br /&gt;
			if (ris_fork == 0)&lt;br /&gt;
				execl(&amp;quot;/bin/sh&amp;quot;,&amp;quot;/bin/sh&amp;quot;,&amp;quot;-c&amp;quot;,buf,0);&lt;br /&gt;
			else&lt;br /&gt;
				wait(&amp;amp;ris_fork);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=682</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=682"/>
		<updated>2014-05-05T12:09:17Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2009.01.30&amp;diff=681</id>
		<title>ProvaTeoria 2009.01.30</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2009.01.30&amp;diff=681"/>
		<updated>2014-05-05T12:07:48Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;=[http://www.cs.unibo.it/~renzo/so/compiti/2009-01-30.tot.pdf TESTO COMPITO]=  ==Esercizio 1== &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; /* Esercizio 1: Scrivere un monitor sbb che implement...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2009-01-30.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Scrivere un monitor sbb che implementi un buffer limitato di caratteri.&lt;br /&gt;
Il monitor deve implmementare le seguenti procedure entry:&lt;br /&gt;
 int sbb.enqueue(char *s);&lt;br /&gt;
 int sbb.dequeue(char *buf, len l);&lt;br /&gt;
Il buffer contiene MAX caratteri. Le stringhe passate alla enqueue sono classiche stringhe del linguaggio C con il carattere &lt;br /&gt;
nullo come terminatore e devono avere lunghezza minore di MAX. Nel caso la stringa s abbia lunghezza maggiore o &lt;br /&gt;
uguale a MAX la stringa non viene caricata nel buffer. Il valore di ritorno e' la lunghezza della stringa inserita nel buffer, -1 &lt;br /&gt;
in caso di errore.&lt;br /&gt;
La dequeue deve restituire una stringa alla volta scrivendola nel buffer. Il parametro l contiene l'ampiezza del buffer (in &lt;br /&gt;
byte in modo simile alla system call &amp;quot;read&amp;quot;).&lt;br /&gt;
Se la stringa non puo' essere memorizzata interamente nel buffer perche' il buffer e' di lunghezza insufficiente viene &lt;br /&gt;
tornato un errore (-1), in modo che il processo chiamante provveda a chiamare nuovamente la funzione specificando un &lt;br /&gt;
buffer di ampiezza maggiore. (N.B. In caso di errore di buffer insufficiente la stringa non deve essere perduta!).&lt;br /&gt;
Il valore di ritorno e' la lunghezza effettiva della stringa presa dal buffer.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
struct attesa_t&lt;br /&gt;
{&lt;br /&gt;
	int mySize;&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
monitor sbb&lt;br /&gt;
{&lt;br /&gt;
	attesa_t * coda_w=queue()&lt;br /&gt;
	int size=0;&lt;br /&gt;
	char **buffer=NULL;&lt;br /&gt;
	procedure entry int enqueue(char*s)&lt;br /&gt;
	{&lt;br /&gt;
		int need=strlen(s);&lt;br /&gt;
		if (need&amp;gt;MAX)&lt;br /&gt;
			return -1; //ho specificato una stringa troppo lunga che non potrà mai essere inserita.&lt;br /&gt;
		else if (MAX-size &amp;lt; need) //non c'è spazio per scrivere: attendo che si liberi&lt;br /&gt;
			coda_w.enqueue(need).wait();&lt;br /&gt;
		insert(buffer,s); //scrivo nel buffer la mia stringa s&lt;br /&gt;
		return need; &lt;br /&gt;
	}&lt;br /&gt;
	procedure entry int dequeue(char*buf,len l)&lt;br /&gt;
	{&lt;br /&gt;
		if (isEmpty(buffer))&lt;br /&gt;
			oktoread.wait(); //buffer vuoto: aspetto che ci sia un elemento.&lt;br /&gt;
		if (strlen(head(buffer))&amp;gt;l)&lt;br /&gt;
			return -1; //spazio insufficiente: aspetto che si liberi. Nel frattempo per evitare la perdita della stringa non faccio signal&lt;br /&gt;
		else&lt;br /&gt;
			{&lt;br /&gt;
			buf=dequeue(buffer); //prelevo la mia stringa e la metto nel buffer&lt;br /&gt;
			if (!isEmpty(buffer)) &lt;br /&gt;
				oktoread.signal();	//buffer non vuoto: sveglio un lettore&lt;br /&gt;
			while(ris!=-1)&lt;br /&gt;
				(searchFor(MAX-size)).signal(); //se c'è spazio per far scrivere qualcuno, lo risveglio.&lt;br /&gt;
											//la searchFor() prende in input un intero n e cerca il primo scrittore&lt;br /&gt;
											//in coda che voglia scrivere meno di n byte. L'operazione continua finché&lt;br /&gt;
											//non ci sono più scrittori disponibili (return -1)&lt;br /&gt;
			return strlen(buf);&lt;br /&gt;
			}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=680</id>
		<title>ProvaTeoria 2011.07.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.07.25&amp;diff=680"/>
		<updated>2014-05-05T11:59:08Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//siano dati tre processi &amp;quot;stampa&amp;quot; come segue:&lt;br /&gt;
//stampa(x):(x=A,T,R) process&lt;br /&gt;
//while (true) {&lt;br /&gt;
// synchro(x);&lt;br /&gt;
// print(x);&lt;br /&gt;
//}&lt;br /&gt;
//scrivere la fuzione synchro() facendo uso di semafori che consenta di avere in output una sequenza infinita&lt;br /&gt;
//di TARATATA (i.e. TARATATATARATATATARATATATARATATATARATATA......)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La soluzione prevede l'utilizzo di 3 semafori, uno per ogni lettera (T,A,R). E' presente anche una variabile buflen contenente&lt;br /&gt;
 la lunghezza della stringa stampata fino ad ora.&lt;br /&gt;
   L'idea si basa sull'utilizzo di una funzione mutex_print() che, a seconda dell'output generato, libera l'opportuno semaforo.&lt;br /&gt;
 Le risorse dei semafori vengono poi richieste dai processi.*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*definizione variabili di supporto e #define*/&lt;br /&gt;
&lt;br /&gt;
#DEFINE T 0&lt;br /&gt;
#DEFINE R 1&lt;br /&gt;
#DEFINE A 2&lt;br /&gt;
int buflen=0;&lt;br /&gt;
&lt;br /&gt;
/*definizione dei semafori*/&lt;br /&gt;
int sem[3];&lt;br /&gt;
sem[T]=1;&lt;br /&gt;
sem[R]=0&lt;br /&gt;
sem[A]=0&lt;br /&gt;
&lt;br /&gt;
/*funzione di supporto: controlla se è arrivato il momento di stampare una R*/&lt;br /&gt;
int checkR(int x)&lt;br /&gt;
{&lt;br /&gt;
  if((x-2)%8==0)&lt;br /&gt;
     return 1;&lt;br /&gt;
  else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void mutex_print()&lt;br /&gt;
{&lt;br /&gt;
if (buflen==0) return;&lt;br /&gt;
else if (buflen%2!=0)&lt;br /&gt;
  v(sem[A]);&lt;br /&gt;
else if (checkR(buflen))&lt;br /&gt;
  v(sem[R]);&lt;br /&gt;
else v(sem[T]);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
void synchro(int x)&lt;br /&gt;
{&lt;br /&gt;
mutex();&lt;br /&gt;
p(sem[x]);&lt;br /&gt;
buflen++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio 3==&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 3: Dato un servizio di message passing asincrono (NON completamente asincrono) e senza fare uso di un &lt;br /&gt;
server implementare un servizio di message passing sincrono LIFO. (cioe' dati asend/arecv, implementare lssend &lt;br /&gt;
lsrecv)&lt;br /&gt;
I messaggi possono essere di grandi dimensioni, si chiede quindi che l'implementazione non crei una coda con tutti i &lt;br /&gt;
messaggi in attesa di essere ricevuti.&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
pid* database=Queue();&lt;br /&gt;
&lt;br /&gt;
void lssend(int dest,message m)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	asend(dest,&amp;quot;#&amp;quot;);&lt;br /&gt;
	do&lt;br /&gt;
	{&lt;br /&gt;
		tmp=arecv(dest);&lt;br /&gt;
	}&lt;br /&gt;
	while(tmp!=&amp;quot;OK&amp;quot;);&lt;br /&gt;
	asend(dest,&amp;quot;OK&amp;quot;)&lt;br /&gt;
	arecv(dest);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
message lsrecv(pid sender)&lt;br /&gt;
{&lt;br /&gt;
	message tmp;&lt;br /&gt;
	pid replier; //replier conterrà il p_id del sender da cui ricevere il messaggio&lt;br /&gt;
	if (sender!=*)&lt;br /&gt;
		{&lt;br /&gt;
			arecv(sender);&lt;br /&gt;
			replier=sender; //devo sicuramente ricevere da questo sender &lt;br /&gt;
		}&lt;br /&gt;
	else&lt;br /&gt;
		{&lt;br /&gt;
			asend(&amp;quot;BOT&amp;quot;,getpid()); //per la lettura del buffer di messaggi&lt;br /&gt;
			tmp=arecv(*);&lt;br /&gt;
			if (tmp==&amp;quot;BOT&amp;quot;)&lt;br /&gt;
			{&lt;br /&gt;
				//coda di messaggi vuota: recupero il primo replier disponibile dal DB&lt;br /&gt;
				replier=db.dequeue();&lt;br /&gt;
				if (replier==NULL)&lt;br /&gt;
				{&lt;br /&gt;
					//coda vuota e DB vuoto: il primo messaggio arrivato è quello da ritornare&lt;br /&gt;
					tmp=arecv(*);&lt;br /&gt;
					replier=tmp.sender;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else do&lt;br /&gt;
			{&lt;br /&gt;
				//cerco l'ultimo messaggio prima di bottom: metto i sender di tutti gli altri messaggi nel DB&lt;br /&gt;
				replier=tmp.sender;&lt;br /&gt;
				tmp=arecv(*);&lt;br /&gt;
				if (tmp!=&amp;quot;BOT&amp;quot;)&lt;br /&gt;
				{&lt;br /&gt;
					db.enqueue(replier);&lt;br /&gt;
					replier=tmp.sender;&lt;br /&gt;
				}	&lt;br /&gt;
			}&lt;br /&gt;
			while (tmp!=&amp;quot;BOT&amp;quot;);&lt;br /&gt;
		//ho trovato il mio replier&lt;br /&gt;
		}&lt;br /&gt;
		asend(replier,&amp;quot;OK&amp;quot;);&lt;br /&gt;
		tmp=arecv(replier);&lt;br /&gt;
		asend(replier,&amp;quot;END&amp;quot;);&lt;br /&gt;
		return tmp;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.01.22&amp;diff=679</id>
		<title>ProvaTeorica 2014.01.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.01.22&amp;diff=679"/>
		<updated>2014-05-05T11:54:22Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2014.01.22.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/compiti/2014.01.22.tot.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Alessandro&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor bridge {&lt;br /&gt;
condition oktomove;	/* auto attraversa il ponte */&lt;br /&gt;
int turn=0;		/*indica il senso delle auto */&lt;br /&gt;
int est=0,ovest=0;      /*contatori delle auto da est e da ovest */&lt;br /&gt;
Queue q;		/*coda delle senso delle macchine in attesa */&lt;br /&gt;
&lt;br /&gt;
procedure entry enter (char EoW)&lt;br /&gt;
{&lt;br /&gt;
	if(EoW == &amp;quot;E&amp;quot;)		/* viene da est */&lt;br /&gt;
	{&lt;br /&gt;
		if(turn == 2 || est &amp;gt;=N || !empty(q))  &lt;br /&gt;
		{&lt;br /&gt;
			q=enqueue(&amp;quot;E&amp;quot;);		/*inserisco nella coda dei sensi*/	&lt;br /&gt;
			oktomove.wait();   	/*aspetta*/&lt;br /&gt;
									&lt;br /&gt;
		}&lt;br /&gt;
	turn = 1;	/*impongo il senso delle auto in circolo nel ponte */&lt;br /&gt;
	est++;&lt;br /&gt;
	}&lt;br /&gt;
	else		/* viene da ovest */&lt;br /&gt;
	{&lt;br /&gt;
		if(turn ==1 || ovest &amp;gt;=N || !empty(q))&lt;br /&gt;
		{&lt;br /&gt;
		        q=enqueue(&amp;quot;O&amp;quot;);		/*inserisco nella coda dei sensi*/&lt;br /&gt;
			oktomove.wait();	/*aspetta*/&lt;br /&gt;
									&lt;br /&gt;
		}&lt;br /&gt;
	turn = 2;	/*impongo il senso delle auto in circolo nel ponte */&lt;br /&gt;
	ovest++;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
procedure entry exit(char EoW)&lt;br /&gt;
{&lt;br /&gt;
	char r;&lt;br /&gt;
	if(EoW == &amp;quot;O&amp;quot;)&lt;br /&gt;
	{&lt;br /&gt;
	est--;&lt;br /&gt;
	r=head(q);                          /* leggo la prossima auto che aspetta di entrare */&lt;br /&gt;
		if(est == 0 || r == &amp;quot;E&amp;quot;)     /*nessuna auto in transito nel ponte o il prossimo va nella stessa direzione*/&lt;br /&gt;
		{&lt;br /&gt;
		est--;&lt;br /&gt;
			if(est == 0)	/*nessuna auto in transito nel ponte */&lt;br /&gt;
			{&lt;br /&gt;
			turn = 0;	/*avanti un altro */&lt;br /&gt;
			}&lt;br /&gt;
			if(!empty(q))&lt;br /&gt;
			{&lt;br /&gt;
			q.dequeue();&lt;br /&gt;
			oktomove.signal();	/*segnale*/&lt;br /&gt;
			}&lt;br /&gt;
                }&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
	ovest--;&lt;br /&gt;
	r=head(q);                          /* leggo la prossima auto che aspetta di entrare */&lt;br /&gt;
		if(ovest == 0 || r == &amp;quot;O&amp;quot;)	 /*nessuna auto in transito nel ponte o il prossimo va nella stessa direzione*/&lt;br /&gt;
		{&lt;br /&gt;
		turn = 0;	/*avanti un altro */&lt;br /&gt;
		}&lt;br /&gt;
		if(!empty(q))&lt;br /&gt;
		{&lt;br /&gt;
		q.dequeue();		&lt;br /&gt;
		oktomove.signal();	/*segnale*/&lt;br /&gt;
	        }&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * URL: http://www.cs.unibo.it/~renzo/so/compiti/2014.01.22.tot.pdf&lt;br /&gt;
 * author: Tommaso Ognibene&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
monitor bridge&lt;br /&gt;
{&lt;br /&gt;
	condition okE;    // attraversare in direzione Est&lt;br /&gt;
	condition okW;    // attraversare in direzione Ovest&lt;br /&gt;
	int n = 0;        // numero di veicoli sul ponte&lt;br /&gt;
	int waitingE = 0; // numero di veicoli che attendono di attraversare in direzione Est&lt;br /&gt;
	int waitingW = 0; // numero di veicoli che attendono di attraversare in direzione Ovest&lt;br /&gt;
	bool toE = true;  // direzione di attraversamento&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter(Vehicle vehicle)&lt;br /&gt;
	{&lt;br /&gt;
		// [Case 1] Il veicolo vuole attraversare in direzione Ovest&lt;br /&gt;
		if (vehicle.To == 'W')&lt;br /&gt;
		{&lt;br /&gt;
			/* Se - il numero di veicoli sul ponte ha raggiunto il massimo; oppure&lt;br /&gt;
			      - qualcuno sta attraversando in direzione opposta; oppure&lt;br /&gt;
			      - qualcuno sta attendendo di attraversare in direzione opposta */&lt;br /&gt;
			if (n == N || (toE &amp;amp;&amp;amp; n &amp;gt; 0) || (!toE &amp;amp;&amp;amp; waitingE &amp;gt; 0))&lt;br /&gt;
			{&lt;br /&gt;
				// Mi fermo e attendo di essere sbloccato&lt;br /&gt;
				waitingW++;&lt;br /&gt;
				okW.wait();&lt;br /&gt;
				waitingW--;&lt;br /&gt;
			}&lt;br /&gt;
			toE = false;&lt;br /&gt;
			n++;&lt;br /&gt;
			&lt;br /&gt;
			/* Se possibile, sblocco eventuali altri veicoli in attesa per la stessa direzione.&lt;br /&gt;
			 * Questo non crea starvation in quanto sono sicuramente un numero limitato. */&lt;br /&gt;
			if (n &amp;lt; N &amp;amp;&amp;amp; waitingE == 0)&lt;br /&gt;
				okW.signal();&lt;br /&gt;
		}&lt;br /&gt;
		// [Case 2] Il veicolo vuole attraversare in direzione Est&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			/* Se - il numero di veicoli sul ponte ha raggiunto il massimo; oppure&lt;br /&gt;
			      - qualcuno sta attraversando in direzione opposta; oppure&lt;br /&gt;
			      - qualcuno sta attendendo di attraversare in direzione opposta */&lt;br /&gt;
			if (n == N || (!toE &amp;amp;&amp;amp; n &amp;gt; 0) || (toE &amp;amp;&amp;amp; waitingW &amp;gt; 0))&lt;br /&gt;
			{&lt;br /&gt;
			        // Mi fermo e attendo di essere sbloccato&lt;br /&gt;
				waitingE++;&lt;br /&gt;
				okE.wait();&lt;br /&gt;
				waitingE--;&lt;br /&gt;
			}&lt;br /&gt;
			toE = true;&lt;br /&gt;
			n++;&lt;br /&gt;
&lt;br /&gt;
			/* Se possibile, sblocco eventuali altri veicoli in attesa per la stessa direzione.&lt;br /&gt;
			 * Questo non crea starvation in quanto sono sicuramente un numero limitato. */&lt;br /&gt;
			if (n &amp;lt; N &amp;amp;&amp;amp; waitingW == 0)&lt;br /&gt;
				okE.signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(Vehicle vehicle)&lt;br /&gt;
	{&lt;br /&gt;
		n--;&lt;br /&gt;
		/* Se nessuno sta attraversando il ponte */&lt;br /&gt;
		if (n == 0)&lt;br /&gt;
		{&lt;br /&gt;
			// [Case 1] L'ultimo ad attraversare andava in direzione Ovest&lt;br /&gt;
			if (vehicle.To == 'W')&lt;br /&gt;
			{&lt;br /&gt;
			   /* Se esiste, attivo il veicolo che per primo si era messo&lt;br /&gt;
			      in attesa per la direzione opposta */&lt;br /&gt;
			   if (waitingE &amp;gt; 0)&lt;br /&gt;
				okE.signal();&lt;br /&gt;
			   else&lt;br /&gt;
				okW.signal();&lt;br /&gt;
			}&lt;br /&gt;
			// [Case 2] L'ultimo ad attraversare andava in direzione Est&lt;br /&gt;
			else&lt;br /&gt;
			{&lt;br /&gt;
			   /* Se esiste, attivo il veicolo che per primo si era messo&lt;br /&gt;
		              in attesa per la direzione opposta */&lt;br /&gt;
			   if (waitingW &amp;gt; 0)&lt;br /&gt;
				okW.signal();&lt;br /&gt;
			   else&lt;br /&gt;
				okE.signal();&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
La Mia soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * author: Midolo&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
Monitor Ponte {&lt;br /&gt;
#define O 0&lt;br /&gt;
#define E 1&lt;br /&gt;
condition oktocross[2];&lt;br /&gt;
int countwaiting[2], crossing;&lt;br /&gt;
&lt;br /&gt;
	bridge.enter(dir){&lt;br /&gt;
		if(crossing != 0 || countwaiting[1-dir] != 0){&lt;br /&gt;
			countwaiting[dir]++;&lt;br /&gt;
			oktocross[dir].wait();&lt;br /&gt;
			countwaiting[dir]--;            &lt;br /&gt;
		}&lt;br /&gt;
		crossing++;&lt;br /&gt;
		if(crossing &amp;lt; N){ &lt;br /&gt;
			oktocross[dir].signal();&lt;br /&gt;
		}    &lt;br /&gt;
	}&lt;br /&gt;
    &lt;br /&gt;
	bridge.exit(dir){&lt;br /&gt;
		crossing--;&lt;br /&gt;
		if(crossing == 0){&lt;br /&gt;
			if(countwaiting[dir] != 0){&lt;br /&gt;
				oktocross[dir].signal();&lt;br /&gt;
			}else{&lt;br /&gt;
				oktocross[1-dir].signal();&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
        &lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Esercizio g.1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&amp;quot;Punto a&amp;quot;&lt;br /&gt;
                123456789123456789123456789...&lt;br /&gt;
                 &lt;br /&gt;
                111111111111111111111111111&lt;br /&gt;
                 22222222222222222222222222          MIN e MAXNUM (infiniti page fault)&lt;br /&gt;
                  3456789993456789993456789&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Punto b&amp;quot;&lt;br /&gt;
                123453453453453453453453453...&lt;br /&gt;
                 &lt;br /&gt;
                111111111111111111111111111&lt;br /&gt;
                 22222222222222222222222222          MIN e MAXNUM (page fault ad ogni accesso)&lt;br /&gt;
                  3453453453453453453453453&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight &amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio c.2==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
message database=Queue():&lt;br /&gt;
&lt;br /&gt;
message msgxchange(pid_t pid, message msg)&lt;br /&gt;
{&lt;br /&gt;
	message ris;&lt;br /&gt;
	asendx(pid,msg);&lt;br /&gt;
	ris=database.Search(pid,getpid());&lt;br /&gt;
	if (ris!=NULL)&lt;br /&gt;
		return ris;&lt;br /&gt;
	do&lt;br /&gt;
	{&lt;br /&gt;
		ris=arecvx();&lt;br /&gt;
		if (ris.sender!=pid)&lt;br /&gt;
			database.Add(ris)&lt;br /&gt;
	}&lt;br /&gt;
	while (ris.sender!=pid);&lt;br /&gt;
	return ris;&lt;br /&gt;
}&lt;br /&gt;
/*	&lt;br /&gt;
Sì, può provocare deadlock. Es:&lt;br /&gt;
&lt;br /&gt;
A: msgxchange(B,msg);&lt;br /&gt;
B: msgxchange(C,msg);&lt;br /&gt;
C: msgxchange(A,msg);&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.01.22&amp;diff=678</id>
		<title>ProvaTeorica 2014.01.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.01.22&amp;diff=678"/>
		<updated>2014-05-05T11:53:20Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2014.01.22.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/compiti/2014.01.22.tot.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Alessandro&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor bridge {&lt;br /&gt;
condition oktomove;	/* auto attraversa il ponte */&lt;br /&gt;
int turn=0;		/*indica il senso delle auto */&lt;br /&gt;
int est=0,ovest=0;      /*contatori delle auto da est e da ovest */&lt;br /&gt;
Queue q;		/*coda delle senso delle macchine in attesa */&lt;br /&gt;
&lt;br /&gt;
procedure entry enter (char EoW)&lt;br /&gt;
{&lt;br /&gt;
	if(EoW == &amp;quot;E&amp;quot;)		/* viene da est */&lt;br /&gt;
	{&lt;br /&gt;
		if(turn == 2 || est &amp;gt;=N || !empty(q))  &lt;br /&gt;
		{&lt;br /&gt;
			q=enqueue(&amp;quot;E&amp;quot;);		/*inserisco nella coda dei sensi*/	&lt;br /&gt;
			oktomove.wait();   	/*aspetta*/&lt;br /&gt;
									&lt;br /&gt;
		}&lt;br /&gt;
	turn = 1;	/*impongo il senso delle auto in circolo nel ponte */&lt;br /&gt;
	est++;&lt;br /&gt;
	}&lt;br /&gt;
	else		/* viene da ovest */&lt;br /&gt;
	{&lt;br /&gt;
		if(turn ==1 || ovest &amp;gt;=N || !empty(q))&lt;br /&gt;
		{&lt;br /&gt;
		        q=enqueue(&amp;quot;O&amp;quot;);		/*inserisco nella coda dei sensi*/&lt;br /&gt;
			oktomove.wait();	/*aspetta*/&lt;br /&gt;
									&lt;br /&gt;
		}&lt;br /&gt;
	turn = 2;	/*impongo il senso delle auto in circolo nel ponte */&lt;br /&gt;
	ovest++;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
procedure entry exit(char EoW)&lt;br /&gt;
{&lt;br /&gt;
	char r;&lt;br /&gt;
	if(EoW == &amp;quot;O&amp;quot;)&lt;br /&gt;
	{&lt;br /&gt;
	est--;&lt;br /&gt;
	r=head(q);                          /* leggo la prossima auto che aspetta di entrare */&lt;br /&gt;
		if(est == 0 || r == &amp;quot;E&amp;quot;)     /*nessuna auto in transito nel ponte o il prossimo va nella stessa direzione*/&lt;br /&gt;
		{&lt;br /&gt;
		est--;&lt;br /&gt;
			if(est == 0)	/*nessuna auto in transito nel ponte */&lt;br /&gt;
			{&lt;br /&gt;
			turn = 0;	/*avanti un altro */&lt;br /&gt;
			}&lt;br /&gt;
			if(!empty(q))&lt;br /&gt;
			{&lt;br /&gt;
			q.dequeue();&lt;br /&gt;
			oktomove.signal();	/*segnale*/&lt;br /&gt;
			}&lt;br /&gt;
                }&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
	ovest--;&lt;br /&gt;
	r=head(q);                          /* leggo la prossima auto che aspetta di entrare */&lt;br /&gt;
		if(ovest == 0 || r == &amp;quot;O&amp;quot;)	 /*nessuna auto in transito nel ponte o il prossimo va nella stessa direzione*/&lt;br /&gt;
		{&lt;br /&gt;
		turn = 0;	/*avanti un altro */&lt;br /&gt;
		}&lt;br /&gt;
		if(!empty(q))&lt;br /&gt;
		{&lt;br /&gt;
		q.dequeue();		&lt;br /&gt;
		oktomove.signal();	/*segnale*/&lt;br /&gt;
	        }&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * URL: http://www.cs.unibo.it/~renzo/so/compiti/2014.01.22.tot.pdf&lt;br /&gt;
 * author: Tommaso Ognibene&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
monitor bridge&lt;br /&gt;
{&lt;br /&gt;
	condition okE;    // attraversare in direzione Est&lt;br /&gt;
	condition okW;    // attraversare in direzione Ovest&lt;br /&gt;
	int n = 0;        // numero di veicoli sul ponte&lt;br /&gt;
	int waitingE = 0; // numero di veicoli che attendono di attraversare in direzione Est&lt;br /&gt;
	int waitingW = 0; // numero di veicoli che attendono di attraversare in direzione Ovest&lt;br /&gt;
	bool toE = true;  // direzione di attraversamento&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter(Vehicle vehicle)&lt;br /&gt;
	{&lt;br /&gt;
		// [Case 1] Il veicolo vuole attraversare in direzione Ovest&lt;br /&gt;
		if (vehicle.To == 'W')&lt;br /&gt;
		{&lt;br /&gt;
			/* Se - il numero di veicoli sul ponte ha raggiunto il massimo; oppure&lt;br /&gt;
			      - qualcuno sta attraversando in direzione opposta; oppure&lt;br /&gt;
			      - qualcuno sta attendendo di attraversare in direzione opposta */&lt;br /&gt;
			if (n == N || (toE &amp;amp;&amp;amp; n &amp;gt; 0) || (!toE &amp;amp;&amp;amp; waitingE &amp;gt; 0))&lt;br /&gt;
			{&lt;br /&gt;
				// Mi fermo e attendo di essere sbloccato&lt;br /&gt;
				waitingW++;&lt;br /&gt;
				okW.wait();&lt;br /&gt;
				waitingW--;&lt;br /&gt;
			}&lt;br /&gt;
			toE = false;&lt;br /&gt;
			n++;&lt;br /&gt;
			&lt;br /&gt;
			/* Se possibile, sblocco eventuali altri veicoli in attesa per la stessa direzione.&lt;br /&gt;
			 * Questo non crea starvation in quanto sono sicuramente un numero limitato. */&lt;br /&gt;
			if (n &amp;lt; N &amp;amp;&amp;amp; waitingE == 0)&lt;br /&gt;
				okW.signal();&lt;br /&gt;
		}&lt;br /&gt;
		// [Case 2] Il veicolo vuole attraversare in direzione Est&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			/* Se - il numero di veicoli sul ponte ha raggiunto il massimo; oppure&lt;br /&gt;
			      - qualcuno sta attraversando in direzione opposta; oppure&lt;br /&gt;
			      - qualcuno sta attendendo di attraversare in direzione opposta */&lt;br /&gt;
			if (n == N || (!toE &amp;amp;&amp;amp; n &amp;gt; 0) || (toE &amp;amp;&amp;amp; waitingW &amp;gt; 0))&lt;br /&gt;
			{&lt;br /&gt;
			        // Mi fermo e attendo di essere sbloccato&lt;br /&gt;
				waitingE++;&lt;br /&gt;
				okE.wait();&lt;br /&gt;
				waitingE--;&lt;br /&gt;
			}&lt;br /&gt;
			toE = true;&lt;br /&gt;
			n++;&lt;br /&gt;
&lt;br /&gt;
			/* Se possibile, sblocco eventuali altri veicoli in attesa per la stessa direzione.&lt;br /&gt;
			 * Questo non crea starvation in quanto sono sicuramente un numero limitato. */&lt;br /&gt;
			if (n &amp;lt; N &amp;amp;&amp;amp; waitingW == 0)&lt;br /&gt;
				okE.signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(Vehicle vehicle)&lt;br /&gt;
	{&lt;br /&gt;
		n--;&lt;br /&gt;
		/* Se nessuno sta attraversando il ponte */&lt;br /&gt;
		if (n == 0)&lt;br /&gt;
		{&lt;br /&gt;
			// [Case 1] L'ultimo ad attraversare andava in direzione Ovest&lt;br /&gt;
			if (vehicle.To == 'W')&lt;br /&gt;
			{&lt;br /&gt;
			   /* Se esiste, attivo il veicolo che per primo si era messo&lt;br /&gt;
			      in attesa per la direzione opposta */&lt;br /&gt;
			   if (waitingE &amp;gt; 0)&lt;br /&gt;
				okE.signal();&lt;br /&gt;
			   else&lt;br /&gt;
				okW.signal();&lt;br /&gt;
			}&lt;br /&gt;
			// [Case 2] L'ultimo ad attraversare andava in direzione Est&lt;br /&gt;
			else&lt;br /&gt;
			{&lt;br /&gt;
			   /* Se esiste, attivo il veicolo che per primo si era messo&lt;br /&gt;
		              in attesa per la direzione opposta */&lt;br /&gt;
			   if (waitingW &amp;gt; 0)&lt;br /&gt;
				okW.signal();&lt;br /&gt;
			   else&lt;br /&gt;
				okE.signal();&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
La Mia soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * author: Midolo&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
Monitor Ponte {&lt;br /&gt;
#define O 0&lt;br /&gt;
#define E 1&lt;br /&gt;
condition oktocross[2];&lt;br /&gt;
int countwaiting[2], crossing;&lt;br /&gt;
&lt;br /&gt;
	bridge.enter(dir){&lt;br /&gt;
		if(crossing != 0 || countwaiting[1-dir] != 0){&lt;br /&gt;
			countwaiting[dir]++;&lt;br /&gt;
			oktocross[dir].wait();&lt;br /&gt;
			countwaiting[dir]--;            &lt;br /&gt;
		}&lt;br /&gt;
		crossing++;&lt;br /&gt;
		if(crossing &amp;lt; N){ &lt;br /&gt;
			oktocross[dir].signal();&lt;br /&gt;
		}    &lt;br /&gt;
	}&lt;br /&gt;
    &lt;br /&gt;
	bridge.exit(dir){&lt;br /&gt;
		crossing--;&lt;br /&gt;
		if(crossing == 0){&lt;br /&gt;
			if(countwaiting[dir] != 0){&lt;br /&gt;
				oktocross[dir].signal();&lt;br /&gt;
			}else{&lt;br /&gt;
				oktocross[1-dir].signal();&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
        &lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Esercizio g.1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&amp;quot;Punto a&amp;quot;&lt;br /&gt;
                123456789123456789123456789...&lt;br /&gt;
                 &lt;br /&gt;
                111111111111111111111111111&lt;br /&gt;
                 22222222222222222222222222          MIN e MAXNUM (infiniti page fault)&lt;br /&gt;
                  3456789993456789993456789&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Punto b&amp;quot;&lt;br /&gt;
                123453453453453453453453453...&lt;br /&gt;
                 &lt;br /&gt;
                111111111111111111111111111&lt;br /&gt;
                 22222222222222222222222222          MIN e MAXNUM (page fault ad ogni accesso)&lt;br /&gt;
                  3453453453453453453453453&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight &amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Esercizio c.2==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void s2send(message m, int dest1,int dest2)&lt;br /&gt;
{&lt;br /&gt;
	asend(dest1,m);&lt;br /&gt;
	asend(dest2,m);&lt;br /&gt;
	arecv(dest1);&lt;br /&gt;
	arecv(dest2);&lt;br /&gt;
	asend(dest1,&amp;quot;OK&amp;quot;);&lt;br /&gt;
	asend(dest2,&amp;quot;OK&amp;quot;);&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
message s2receive(sender)&lt;br /&gt;
{&lt;br /&gt;
	message ris=arecv(sender);&lt;br /&gt;
	asend(sender,&amp;quot;OK&amp;quot;);&lt;br /&gt;
	arecv(sender);&lt;br /&gt;
	return ris;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=676</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=676"/>
		<updated>2014-05-04T15:30:40Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List() /*lista di condizioni, una per ogni processo arrivato*/&lt;br /&gt;
	int* procstack=Stack(); /*stack di processi per l'uscita LIFO*/&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){ /*cioè se il processo non è in cima allo stack*/&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait(); /*aggiungo il mio p_id alla lista di condizioni e mi metto in wait*/&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione&lt;br /&gt;
&lt;br /&gt;
==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
pid index[N] /*index contiene gli id dei vari server*/&lt;br /&gt;
&lt;br /&gt;
struct serverMSG&lt;br /&gt;
{&lt;br /&gt;
	pid readers=Queue(); &lt;br /&gt;
	message m;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*Database di strutture server msg: contiene una lista di tutti i messaggi arrivati e, per ogni messaggio, quanti server l'hanno letto*/&lt;br /&gt;
&lt;br /&gt;
serverMSG* database=Queue(); &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
process server[i=0...N-1]()&lt;br /&gt;
{&lt;br /&gt;
	message mymsg;&lt;br /&gt;
	struct serverMSG* tmp;&lt;br /&gt;
	while(1)&lt;br /&gt;
	{&lt;br /&gt;
		mymsg=arecv(*);&lt;br /&gt;
		if (mymsg==&amp;quot;###&amp;quot;) //è arrivato il messaggio speciale che mi indica di guardare il database&lt;br /&gt;
		{&lt;br /&gt;
			while(tmp=read(database)) //La funzione read ritorna in ordine (dalla più vecchia alla più nuova) le strutture presenti nel DB&lt;br /&gt;
			{&lt;br /&gt;
				if (!tmp-&amp;gt;readers.found(getpid())) //non ho trovato il mio pid tra la lista dei lettori di quel messaggio&lt;br /&gt;
				{&lt;br /&gt;
					print(tmp-&amp;gt;message); //&lt;br /&gt;
					tmp-&amp;gt;readers.enqueue(getpid()); //mi aggiungo alla lista dei lettori&lt;br /&gt;
					if (tmp-&amp;gt;readers.sizeOf()==N)&lt;br /&gt;
						remove(tmp);			//se tutti hanno letto quel messaggio lo rimuovo dalla lista		&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			database.enqueue(NULL,message); //aggiungo il messaggio settando come coda di lettori NULL&lt;br /&gt;
			foreach(i in index)&lt;br /&gt;
			{&lt;br /&gt;
				send(&amp;quot;###&amp;quot;,index[i]); // a tutti arriva un messaggio speciale che dice di guardare il DB&lt;br /&gt;
			}&lt;br /&gt;
		&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=675</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=675"/>
		<updated>2014-05-04T15:17:54Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List() /*lista di condizioni, una per ogni processo arrivato*/&lt;br /&gt;
	int* procstack=Stack(); /*stack di processi per l'uscita LIFO*/&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){ /*cioè se il processo non è in cima allo stack*/&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait(); /*aggiungo il mio p_id alla lista di condizioni e mi metto in wait*/&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione&lt;br /&gt;
&lt;br /&gt;
==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
pid index[N] /*index contiene gli id dei vari server*/&lt;br /&gt;
&lt;br /&gt;
struct serverMSG&lt;br /&gt;
{&lt;br /&gt;
	pid readers=Queue();&lt;br /&gt;
	message m;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
serverMSG* database=Queue();&lt;br /&gt;
&lt;br /&gt;
process server[i=0...N-1]()&lt;br /&gt;
{&lt;br /&gt;
	message mymsg;&lt;br /&gt;
	struct serverMSG* tmp;&lt;br /&gt;
	while(1)&lt;br /&gt;
	{&lt;br /&gt;
		mymsg=arecv(*);&lt;br /&gt;
		if (mymsg==&amp;quot;###&amp;quot;);&lt;br /&gt;
		{&lt;br /&gt;
			while(tmp=read(database))&lt;br /&gt;
			{&lt;br /&gt;
				if (!tmp-&amp;gt;readers.found(getpid()))&lt;br /&gt;
				{&lt;br /&gt;
					print(tmp-&amp;gt;message);&lt;br /&gt;
					tmp-&amp;gt;readers.enqueue(getpid());&lt;br /&gt;
					if (tmp-&amp;gt;readers.sizeOf()==N)&lt;br /&gt;
						remove(tmp);					&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			database.enqueue(NULL,message);&lt;br /&gt;
			foreach(i in index)&lt;br /&gt;
			{&lt;br /&gt;
				send(&amp;quot;###&amp;quot;,index[i]);&lt;br /&gt;
			}&lt;br /&gt;
		&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=649</id>
		<title>ProvaTeoria 2011.01.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=649"/>
		<updated>2014-04-30T15:05:30Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2011-01-17.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Scrivere un monitor reqq che gestisca una coda di richieste.&lt;br /&gt;
I richiedenti chiamano la funzione che ha la seguente signature:&lt;br /&gt;
answer_t reqq.query(request_t request);&lt;br /&gt;
Query deve fermare il processo richiedente fino a completamento della richiesta da parte di un gestore. Il valore di ritorno &lt;br /&gt;
e' la risposta del gestore.&lt;br /&gt;
Ci sono N gestori che si comportano come segue:&lt;br /&gt;
multiq_handler: process[i, i=0,..,N-1] {&lt;br /&gt;
	request_t req;&lt;br /&gt;
	int type;&lt;br /&gt;
	while (1) {&lt;br /&gt;
		 req=reqq.getquery(i);&lt;br /&gt;
		 reqq.reply(i,handle(req));&lt;br /&gt;
 	}&lt;br /&gt;
}&lt;br /&gt;
Le richieste vengono assegnate ai gestori disponibili o accodate se sono tutti impegnati. Quando un gestore termina la &lt;br /&gt;
gestione (funzione handle, che non implementare!) invia il risultato tramite la reply. Il valore passato alla reply deve &lt;br /&gt;
essere restituito al richiedente come valore di ritorno della funzione query. Se non vi sono richieste disponibili i gestori si &lt;br /&gt;
fermano attendendo nuove richieste.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La mia soluzione si basa su una struttura reqEntry contenente un campo per la domanda, uno per la risposta, una condizione oktoexit e un intero per il gestore.&lt;br /&gt;
Quando arriva un richiedente inserisce una struttura con una domanda e con i campi risposta e gestore vuoti.&lt;br /&gt;
Quando un gestore si occupa di una domanda setta l'opportuno campo gestore al suo indice e, al termine della routine handle(), inserisce la sua risposta nell'opportuno&lt;br /&gt;
campo della struct risvegliando il richiedente*/&lt;br /&gt;
&lt;br /&gt;
struct reqEntry&lt;br /&gt;
{&lt;br /&gt;
	request_t req;&lt;br /&gt;
	condition oktoexit;&lt;br /&gt;
	answer_t reply=NULL;&lt;br /&gt;
	int handler=VOID; //VOID è un valore speciale avente valore diverso dagli indici dei gestori&lt;br /&gt;
}&lt;br /&gt;
monitor reqq&lt;br /&gt;
{&lt;br /&gt;
	reqEntry* rq=Queue(); /*coda di reqEntry*/&lt;br /&gt;
	condition oktohandle; /*per i gestori*/&lt;br /&gt;
	answer_t procedure entry query(request_t request)&lt;br /&gt;
	{&lt;br /&gt;
		rq.insert(request); &lt;br /&gt;
		rp=rq.searchByReq(request);&lt;br /&gt;
		oktohandle.signal(); /*cerco se esiste un gestore in attesa per la mia richiesta*/&lt;br /&gt;
		rp-&amp;gt;oktoexit.wait();&lt;br /&gt;
		risp=rp-&amp;gt;reply; &lt;br /&gt;
		remove(rp); /*recupero la risposta e rimuovo la struct dalla coda*/&lt;br /&gt;
		return risp;	&lt;br /&gt;
	}&lt;br /&gt;
	request_t procedure entry  getquery(int index)&lt;br /&gt;
	{&lt;br /&gt;
		if isEmptyFree(rq) /*isEmptyFree ritorna 1 se non ci sono struct libere (cioè con handler VOID) nella coda di reqEntry*/&lt;br /&gt;
		{&lt;br /&gt;
			oktohandle.wait();&lt;br /&gt;
		}&lt;br /&gt;
		rp=rq.searchFree(); /*restituisce un elemento della coda di reqEntry avente handler VOID*/&lt;br /&gt;
		rp-&amp;gt;handler=index; &lt;br /&gt;
		return rp;&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry reply(int index, answer_t rep)&lt;br /&gt;
	{&lt;br /&gt;
		rp=rq.searchByHandler(index); /*cerca nella lista la struct avente handler uguale al mio indice*/&lt;br /&gt;
		rp-&amp;gt;reply=rep;&lt;br /&gt;
		rp-&amp;gt;oktoexit.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=640</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=640"/>
		<updated>2014-04-30T13:53:13Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List() /*lista di condizioni, una per ogni processo arrivato*/&lt;br /&gt;
	int* procstack=Stack(); /*stack di processi per l'uscita LIFO*/&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){ /*cioè se il processo non è in cima allo stack*/&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait(); /*aggiungo il mio p_id alla lista di condizioni e mi metto in wait*/&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=638</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=638"/>
		<updated>2014-04-30T13:48:51Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=637</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=637"/>
		<updated>2014-04-30T13:47:46Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teoria 2012.01.12]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=636</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=636"/>
		<updated>2014-04-30T13:47:24Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2012.01.12]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=630</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=630"/>
		<updated>2014-04-30T09:51:17Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List() /*lista di condizioni, una per ogni processo arrivato*/&lt;br /&gt;
	int* procstack=Stack(); /*stack di processi per l'uscita LIFO*/&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){ /*cioè se il processo non è in cima allo stack*/&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait(); /*aggiungo il mio p_id alla lista di condizioni e mi metto in wait*/&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione XD&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=629</id>
		<title>ProvaTeoria 2012.01.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2012.01.12&amp;diff=629"/>
		<updated>2014-04-30T09:49:52Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=  ==Esercizio 1== &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; monitor seq { 	condition* c=List() 	int* procstack=St...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2012-01-12.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor seq&lt;br /&gt;
{&lt;br /&gt;
	condition* c=List()&lt;br /&gt;
	int* procstack=Stack();&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		procstack.push(this-&amp;gt;p_id);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		if (procstack.Top()!=this-&amp;gt;p_id){&lt;br /&gt;
			List.insert(this-&amp;gt;p_id);&lt;br /&gt;
			(List.search(this-&amp;gt;p_id)).wait();&lt;br /&gt;
			}&lt;br /&gt;
		List.remove(this-&amp;gt;p_id);&lt;br /&gt;
		procstack.Pop();&lt;br /&gt;
		List.search(procstack.Top()).signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTA: Con questa soluzione se l'ultimo processo chiama la exit e ci sono altri processi in coda, gli altri processi usciranno prima che l'ultimo esca dallo urgent stack per uscire a sua volta, quindi non credo che rispetti la traccia.&lt;br /&gt;
Però non ho trovato un'altra soluzione XD&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2010.05.12&amp;diff=628</id>
		<title>ProvaTeoria 2010.05.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2010.05.12&amp;diff=628"/>
		<updated>2014-04-30T09:44:23Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2010-05-12.ris.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Due nazioni limitrofe che chiameremo 0 e 1 hanno stabilito un numero massimo MAXIMM di immigrati che &lt;br /&gt;
soggiornano nell'altra nazione.&lt;br /&gt;
Quando un cittadino di una nazione vuole andare nell'altra, alla frontiera di rivolge agli ufficiali di immigrazione dell'altra &lt;br /&gt;
nazione e viene posto in attesa se il numero massimo di immigrati e' stato gia' raggiunto in una delle due nazioni.&lt;br /&gt;
Pertanto il cittadino di 0 che vuole andare in 1 viene messo in stato di attesa sia se ci sono gia' MAXIMM cittadini di 0 in 1 &lt;br /&gt;
sia se ci sono MAXIMM cittadini di 1 in 0.&lt;br /&gt;
La “vita” dei cittadini e' quindi:&lt;br /&gt;
cittadinoi, j&lt;br /&gt;
,i∈{0,1} , j∈1,... , Ncittadinii&lt;br /&gt;
:&lt;br /&gt;
 while(1) {&lt;br /&gt;
 immigration01.emigrate(i); ….&lt;br /&gt;
 immigration01.returnhome(i); ….&lt;br /&gt;
 }&lt;br /&gt;
Il problema (non la soluzione) presenta problemi di deadlock o di starvation?&lt;br /&gt;
Scrivere il monitor immigration01 con due procedure entry emigrate(int citizenship) e returnhome(int citizenship).&lt;br /&gt;
(il parametro e' la propria cittadinanza, I cittadini di 0 mettono 0 come parametro e quindi vogliono andare in 1, e &lt;br /&gt;
viceversa).&lt;br /&gt;
La soluzione chiaramente non deve inserire problemi di deadlock o di starvation che non siano propri del problema.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor immigration01&lt;br /&gt;
{&lt;br /&gt;
	int ImmIn[i]; /*i=0,1*/&lt;br /&gt;
	condition oktopass; &lt;br /&gt;
	procedure entry emigrate(int i)&lt;br /&gt;
	&lt;br /&gt;
	{&lt;br /&gt;
		if (ImmIn[!i]==MAXIMM || ImmIn[i]==MAXIMM)&lt;br /&gt;
			oktopass.wait();&lt;br /&gt;
		ImmIn[!i]++;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry returnhome(int i)&lt;br /&gt;
	{&lt;br /&gt;
		ImmIn[!i]--;&lt;br /&gt;
		if (ImmIn[i]&amp;lt;MAXIMM)&lt;br /&gt;
			oktopass.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
NOTA: Dalla traccia mi è sembrato di capire che quando un cittadino della nazione i vuole tornare a casa non c'è bisogno di controllare che il numero di immigrati delle due nazioni sia minore di MAXIMM. Infatti si precisa che quel controllo va fatto solo per cittadini di una nazione che vogliano andare nell'altra. Però non sono sicuro di aver interpretato in maniera corretta.&lt;br /&gt;
Basandomi su questa assunzione, inoltre, credo che non possano esserci né deadlock né starvation, ma al massimo un'attesa inutile da parte degli emigranti di una nazione che devono aspettare che la propria soglia di immigrati diminuisca prima di emigrare.&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2010.05.12&amp;diff=627</id>
		<title>ProvaTeoria 2010.05.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2010.05.12&amp;diff=627"/>
		<updated>2014-04-30T09:42:54Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;=[http://www.cs.unibo.it/~renzo/so/compiti/2010-05-12.ris.pdf TESTO COMPITO]=  ==Esercizio 1==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; /* Esercizio 1: Due nazioni limitrofe che chiameremo...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2010-05-12.ris.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Due nazioni limitrofe che chiameremo 0 e 1 hanno stabilito un numero massimo MAXIMM di immigrati che &lt;br /&gt;
soggiornano nell'altra nazione.&lt;br /&gt;
Quando un cittadino di una nazione vuole andare nell'altra, alla frontiera di rivolge agli ufficiali di immigrazione dell'altra &lt;br /&gt;
nazione e viene posto in attesa se il numero massimo di immigrati e' stato gia' raggiunto in una delle due nazioni.&lt;br /&gt;
Pertanto il cittadino di 0 che vuole andare in 1 viene messo in stato di attesa sia se ci sono gia' MAXIMM cittadini di 0 in 1 &lt;br /&gt;
sia se ci sono MAXIMM cittadini di 1 in 0.&lt;br /&gt;
La “vita” dei cittadini e' quindi:&lt;br /&gt;
cittadinoi, j&lt;br /&gt;
,i∈{0,1} , j∈1,... , Ncittadinii&lt;br /&gt;
:&lt;br /&gt;
 while(1) {&lt;br /&gt;
 immigration01.emigrate(i); ….&lt;br /&gt;
 immigration01.returnhome(i); ….&lt;br /&gt;
 }&lt;br /&gt;
Il problema (non la soluzione) presenta problemi di deadlock o di starvation?&lt;br /&gt;
Scrivere il monitor immigration01 con due procedure entry emigrate(int citizenship) e returnhome(int citizenship).&lt;br /&gt;
(il parametro e' la propria cittadinanza, I cittadini di 0 mettono 0 come parametro e quindi vogliono andare in 1, e &lt;br /&gt;
viceversa).&lt;br /&gt;
La soluzione chiaramente non deve inserire problemi di deadlock o di starvation che non siano propri del problema.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor immigration01&lt;br /&gt;
{&lt;br /&gt;
	int ImmIn[i]; /*i=0,1*/&lt;br /&gt;
	condition oktopass; &lt;br /&gt;
	procedure entry emigrate(int i)&lt;br /&gt;
	&lt;br /&gt;
	{&lt;br /&gt;
		if (ImmIn[!i]==MAXIMM || ImmIn[i]==MAXIMM)&lt;br /&gt;
			oktopass.wait();&lt;br /&gt;
		ImmIn[!i]++;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry returnhome(int i)&lt;br /&gt;
	{&lt;br /&gt;
		ImmIn[!i]--;&lt;br /&gt;
		if (ImmIn[i]&amp;lt;MAXIMM)&lt;br /&gt;
			oktopass.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
NOTA: Dalla traccia mi è sembrato di capire che quando un cittadino della nazione i vuole tornare a casa non c'è bisogno di controllare che il numero di immigrati delle due nazioni sia minore di maximm. Infatti si precisa che quel controllo va fatto solo per cittadini di una nazione che vogliano andare nell'altra.&lt;br /&gt;
Basandomi su questa assunzione, inoltre, credo che non possano esserci né deadlock né starvation, ma al massimo un'attesa inutile da parte degli emigranti di una nazione che devono aspettare che la propria soglia di immigrati diminuisca prima di emigrare.&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=626</id>
		<title>ProvaTeoria 2011.01.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=626"/>
		<updated>2014-04-30T09:39:45Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2011-01-17.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Scrivere un monitor reqq che gestisca una coda di richieste.&lt;br /&gt;
I richiedenti chiamano la funzione che ha la seguente signature:&lt;br /&gt;
answer_t reqq.query(request_t request);&lt;br /&gt;
Query deve fermare il processo richiedente fino a completamento della richiesta da parte di un gestore. Il valore di ritorno &lt;br /&gt;
e' la risposta del gestore.&lt;br /&gt;
Ci sono N gestori che si comportano come segue:&lt;br /&gt;
multiq_handler: process[i, i=0,..,N-1] {&lt;br /&gt;
	request_t req;&lt;br /&gt;
	int type;&lt;br /&gt;
	while (1) {&lt;br /&gt;
		 req=reqq.getquery(i);&lt;br /&gt;
		 reqq.reply(i,handle(req));&lt;br /&gt;
 	}&lt;br /&gt;
}&lt;br /&gt;
Le richieste vengono assegnate ai gestori disponibili o accodate se sono tutti impegnati. Quando un gestore termina la &lt;br /&gt;
gestione (funzione handle, che non implementare!) invia il risultato tramite la reply. Il valore passato alla reply deve &lt;br /&gt;
essere restituito al richiedente come valore di ritorno della funzione query. Se non vi sono richieste disponibili i gestori si &lt;br /&gt;
fermano attendendo nuove richieste.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La mia soluzione si basa su una struttura reqEntry contenente un campo per la domanda, uno per la risposta, una condizione oktoexit e un intero per il gestore.&lt;br /&gt;
Quando arriva un richiedente inserisce una struttura con una domanda e con i campi risposta e gestore vuoti.&lt;br /&gt;
Quando un gestore si occupa di una domanda setta l'opportuno campo gestore al suo indice e, al termine della routine handle(), inserisce la sua risposta nell'opportuno&lt;br /&gt;
campo della struct risvegliando il richiedente*/&lt;br /&gt;
&lt;br /&gt;
struct reqEntry&lt;br /&gt;
{&lt;br /&gt;
	request_t req;&lt;br /&gt;
	condition oktoexit;&lt;br /&gt;
	answer_t reply=NULL;&lt;br /&gt;
	int handler=VOID; //VOID è un valore speciale avente valore diverso dagli indici dei gestori&lt;br /&gt;
}&lt;br /&gt;
monitor reqq&lt;br /&gt;
{&lt;br /&gt;
	reqEntry* rq=Queue(); /*coda di reqEntry*/&lt;br /&gt;
	condition oktohandle; /*per i gestori*/&lt;br /&gt;
	answer_t procedure entry query(request_t request)&lt;br /&gt;
	{&lt;br /&gt;
		rq.insert(request); &lt;br /&gt;
		rp=rq.searchByReq(request);&lt;br /&gt;
		oktohandle.signal(); /*cerco se esiste un gestore in attesa per la mia richiesta*/&lt;br /&gt;
		if (rp-&amp;gt;reply==NULL) /*la richiesta non ha avuto risposta*/&lt;br /&gt;
			rp-&amp;gt;oktoexit.wait();&lt;br /&gt;
		risp=rp-&amp;gt;reply; &lt;br /&gt;
		remove(rp); /*recupero la risposta e rimuovo la struct dalla coda*/&lt;br /&gt;
		return risp;	&lt;br /&gt;
	}&lt;br /&gt;
	request_t procedure entry  getquery(int index)&lt;br /&gt;
	{&lt;br /&gt;
		if isEmptyFree(rq) /*isEmptyFree ritorna 1 se non ci sono struct libere (cioè con handler VOID) nella coda di reqEntry*/&lt;br /&gt;
		{&lt;br /&gt;
			oktohandle.wait();&lt;br /&gt;
		}&lt;br /&gt;
		rp=rq.searchFree(); /*restituisce un elemento della coda di reqEntry avente handler VOID*/&lt;br /&gt;
		rp-&amp;gt;handler=index; &lt;br /&gt;
		return rp;&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry reply(int index, answer_t rep)&lt;br /&gt;
	{&lt;br /&gt;
		rp=rq.searchByHandler(index); /*cerca nella lista la struct avente handler uguale al mio indice*/&lt;br /&gt;
		rp-&amp;gt;reply=rep;&lt;br /&gt;
		rp-&amp;gt;oktoexit.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=625</id>
		<title>ProvaTeoria 2011.01.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeoria_2011.01.17&amp;diff=625"/>
		<updated>2014-04-30T08:11:01Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;=[http://www.cs.unibo.it/~renzo/so/compiti/2009-09-18.tot.pdf TESTO COMPITO]=  ==Esercizio 1==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; /* Esercizio 1: Scrivere un monitor reqq che gestisc...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2009-09-18.tot.pdf TESTO COMPITO]=&lt;br /&gt;
&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Esercizio 1: Scrivere un monitor reqq che gestisca una coda di richieste.&lt;br /&gt;
I richiedenti chiamano la funzione che ha la seguente signature:&lt;br /&gt;
answer_t reqq.query(request_t request);&lt;br /&gt;
Query deve fermare il processo richiedente fino a completamento della richiesta da parte di un gestore. Il valore di ritorno &lt;br /&gt;
e' la risposta del gestore.&lt;br /&gt;
Ci sono N gestori che si comportano come segue:&lt;br /&gt;
multiq_handler: process[i, i=0,..,N-1] {&lt;br /&gt;
	request_t req;&lt;br /&gt;
	int type;&lt;br /&gt;
	while (1) {&lt;br /&gt;
		 req=reqq.getquery(i);&lt;br /&gt;
		 reqq.reply(i,handle(req));&lt;br /&gt;
 	}&lt;br /&gt;
}&lt;br /&gt;
Le richieste vengono assegnate ai gestori disponibili o accodate se sono tutti impegnati. Quando un gestore termina la &lt;br /&gt;
gestione (funzione handle, che non implementare!) invia il risultato tramite la reply. Il valore passato alla reply deve &lt;br /&gt;
essere restituito al richiedente come valore di ritorno della funzione query. Se non vi sono richieste disponibili i gestori si &lt;br /&gt;
fermano attendendo nuove richieste.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*La mia soluzione si basa su una struttura reqEntry contenente un campo per la domanda, uno per la risposta, una condizione oktoexit e un intero per il gestore.&lt;br /&gt;
Quando arriva un richiedente inserisce una struttura con una domanda e con i campi risposta e gestore vuoti.&lt;br /&gt;
Quando un gestore si occupa di una domanda setta l'opportuno campo gestore al suo indice e, al termine della routine handle(), inserisce la sua risposta nell'opportuno&lt;br /&gt;
campo della struct risvegliando il richiedente*/&lt;br /&gt;
&lt;br /&gt;
struct reqEntry&lt;br /&gt;
{&lt;br /&gt;
	request_t req;&lt;br /&gt;
	condition oktoexit;&lt;br /&gt;
	answer_t reply=NULL;&lt;br /&gt;
	int handler=VOID; //VOID è un valore speciale avente valore diverso dagli indici dei gestori&lt;br /&gt;
}&lt;br /&gt;
monitor reqq&lt;br /&gt;
{&lt;br /&gt;
	reqEntry* rq=Queue(); /*coda di reqEntry*/&lt;br /&gt;
	condition oktohandle; /*per i gestori*/&lt;br /&gt;
	answer_t procedure entry query(request_t request)&lt;br /&gt;
	{&lt;br /&gt;
		rq.insert(request); &lt;br /&gt;
		rp=rq.searchByReq(request);&lt;br /&gt;
		oktohandle.signal(); /*cerco se esiste un gestore in attesa per la mia richiesta*/&lt;br /&gt;
		if (rp-&amp;gt;reply==NULL) /*la richiesta non ha avuto risposta*/&lt;br /&gt;
			rp-&amp;gt;oktoexit.wait();&lt;br /&gt;
		risp=rp-&amp;gt;reply; &lt;br /&gt;
		remove(rp); /*recupero la risposta e rimuovo la struct dalla coda*/&lt;br /&gt;
		return risp;	&lt;br /&gt;
	}&lt;br /&gt;
	request_t procedure entry  getquery(int index)&lt;br /&gt;
	{&lt;br /&gt;
		if isEmptyFree(rq) /*isEmptyFree ritorna 1 se non ci sono struct libere (cioè con handler VOID) nella coda di reqEntry*/&lt;br /&gt;
		{&lt;br /&gt;
			oktohandle.wait();&lt;br /&gt;
		}&lt;br /&gt;
		rp=rq.searchFree(); /*restituisce un elemento della coda di reqEntry avente handler VOID*/&lt;br /&gt;
		rp-&amp;gt;handler=index; &lt;br /&gt;
		return rp;&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry reply(int index, answer_t rep)&lt;br /&gt;
	{&lt;br /&gt;
		rp=rq.searchByHandler(index); /*cerca nella lista la struct avente handler uguale al mio indice*/&lt;br /&gt;
		rp-&amp;gt;reply=rep;&lt;br /&gt;
		rp-&amp;gt;oktoexit.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=609</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=609"/>
		<updated>2014-04-28T14:06:48Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.01.15&amp;diff=608</id>
		<title>ProvaPratica 2009.01.15</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.01.15&amp;diff=608"/>
		<updated>2014-04-28T14:05:05Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-01-15.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 e 2 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
&lt;br /&gt;
Esercizio1 (obbligatorio): (15 punti) Scrivere un programma in linguaggio C &amp;quot;respawn&amp;quot; che provveda a riattivare un &lt;br /&gt;
programma quando questo termina (Naturalmante o erroneamente). Es:&lt;br /&gt;
respawn test a b c&lt;br /&gt;
lancia il programma &amp;quot;test a b c&amp;quot;. Se e quando questo dovesse terminare ne viene lanciato un altro uguale.&lt;br /&gt;
&lt;br /&gt;
Esercizio 2: completamento dell'esercizio 1. (5 punti)&lt;br /&gt;
Modificare il programma dell'esercizio 1 per riattivare il programma solo se termina in modo anormale (per un segnale)&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc,char*argv[])&lt;br /&gt;
{&lt;br /&gt;
	int ris;&lt;br /&gt;
	ris=fork();&lt;br /&gt;
	while(ris&amp;gt;0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;%d\n&amp;quot;,ris);&lt;br /&gt;
		wait(&amp;amp;ris);&lt;br /&gt;
		if (WIFSIGNALED(ris))&lt;br /&gt;
			ris=fork();&lt;br /&gt;
		else&lt;br /&gt;
			return(0);&lt;br /&gt;
	}&lt;br /&gt;
	execvp(argv[1],argv+1);&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.01.15&amp;diff=607</id>
		<title>ProvaPratica 2009.01.15</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.01.15&amp;diff=607"/>
		<updated>2014-04-28T14:04:27Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-01-15.pdf&amp;lt;/h1&amp;gt;   == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;  #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;unistd.h&amp;gt;  i...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-01-15.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc,char*argv[])&lt;br /&gt;
{&lt;br /&gt;
	int ris;&lt;br /&gt;
	ris=fork();&lt;br /&gt;
	while(ris&amp;gt;0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;%d\n&amp;quot;,ris);&lt;br /&gt;
		wait(&amp;amp;ris);&lt;br /&gt;
		if (WIFSIGNALED(ris))&lt;br /&gt;
			ris=fork();&lt;br /&gt;
		else&lt;br /&gt;
			return(0);&lt;br /&gt;
	}&lt;br /&gt;
	execvp(argv[1],argv+1);&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.02.12&amp;diff=606</id>
		<title>ProvaPratica 2009.02.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.02.12&amp;diff=606"/>
		<updated>2014-04-28T14:02:38Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-02-12.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void usage()&lt;br /&gt;
{&lt;br /&gt;
	printf(&amp;quot;usage: ./invarg.out EXEC_NAME [ARG1] [ARG2] ... [ARGN]\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc,char* argv[])&lt;br /&gt;
{&lt;br /&gt;
   char* tmp_i,*tmp_x;&lt;br /&gt;
   int x=(argc-1),i=2;&lt;br /&gt;
   if (argc&amp;lt;2)&lt;br /&gt;
   {&lt;br /&gt;
   		usage();&lt;br /&gt;
   		return(1);&lt;br /&gt;
   }&lt;br /&gt;
   while(i&amp;lt;x)&lt;br /&gt;
   {&lt;br /&gt;
       tmp_i=argv[i];&lt;br /&gt;
       tmp_x=argv[x];&lt;br /&gt;
       argv[i]=tmp_x;&lt;br /&gt;
       argv[x]=tmp_i;&lt;br /&gt;
       i++;&lt;br /&gt;
       x--;&lt;br /&gt;
   }&lt;br /&gt;
	for(i=0;i&amp;lt;argc-1;i++)&lt;br /&gt;
		argv[i]=argv[i+1];&lt;br /&gt;
	&lt;br /&gt;
	argv[argc-1]=NULL;&lt;br /&gt;
	argc--;&lt;br /&gt;
	execvp(argv[0],argv);&lt;br /&gt;
        //equivalentemente avrei potuto lanciare execvp(argv[1],argv+1) evitando di modificare argv[]&lt;br /&gt;
	return 0;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.02.12&amp;diff=605</id>
		<title>ProvaPratica 2009.02.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.02.12&amp;diff=605"/>
		<updated>2014-04-28T14:01:08Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-02-12.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void usage()&lt;br /&gt;
{&lt;br /&gt;
	printf(&amp;quot;usage: ./invarg.out EXEC_NAME [ARG1] [ARG2] ... [ARGN]\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc,char* argv[])&lt;br /&gt;
{&lt;br /&gt;
   char* tmp_i,*tmp_x;&lt;br /&gt;
   int x=(argc-1),i=2;&lt;br /&gt;
   if (argc&amp;lt;2)&lt;br /&gt;
   {&lt;br /&gt;
   		usage();&lt;br /&gt;
   		return(1);&lt;br /&gt;
   }&lt;br /&gt;
   while(i&amp;lt;x)&lt;br /&gt;
   {&lt;br /&gt;
       tmp_i=argv[i];&lt;br /&gt;
       tmp_x=argv[x];&lt;br /&gt;
       argv[i]=tmp_x;&lt;br /&gt;
       argv[x]=tmp_i;&lt;br /&gt;
       i++;&lt;br /&gt;
       x--;&lt;br /&gt;
   }&lt;br /&gt;
	for(i=0;i&amp;lt;argc-1;i++)&lt;br /&gt;
		argv[i]=argv[i+1];&lt;br /&gt;
	&lt;br /&gt;
	argv[argc-1]=NULL;&lt;br /&gt;
	argc--;&lt;br /&gt;
	execvp(argv[0],argv);&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.02.12&amp;diff=604</id>
		<title>ProvaPratica 2009.02.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.02.12&amp;diff=604"/>
		<updated>2014-04-28T14:00:47Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-02-12.pdf&amp;lt;/h1&amp;gt;   == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;string.h&amp;gt; #in...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2009-02-12.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void usage()&lt;br /&gt;
{&lt;br /&gt;
	printf(&amp;quot;usage: ./invarg.out EXEC_NAME [ARG1] [ARG2] ... [ARGN]\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc,char* argv[])&lt;br /&gt;
{&lt;br /&gt;
   char* tmp_i,*tmp_x,*bin=&amp;quot;/bin/&amp;quot;;&lt;br /&gt;
   int x=(argc-1),i=2;&lt;br /&gt;
   if (argc&amp;lt;2)&lt;br /&gt;
   {&lt;br /&gt;
   		usage();&lt;br /&gt;
   		return(1);&lt;br /&gt;
   }&lt;br /&gt;
   while(i&amp;lt;x)&lt;br /&gt;
   {&lt;br /&gt;
       tmp_i=argv[i];&lt;br /&gt;
       tmp_x=argv[x];&lt;br /&gt;
       argv[i]=tmp_x;&lt;br /&gt;
       argv[x]=tmp_i;&lt;br /&gt;
       i++;&lt;br /&gt;
       x--;&lt;br /&gt;
   }&lt;br /&gt;
	for(i=0;i&amp;lt;argc-1;i++)&lt;br /&gt;
		argv[i]=argv[i+1];&lt;br /&gt;
	&lt;br /&gt;
	argv[argc-1]=NULL;&lt;br /&gt;
	argc--;&lt;br /&gt;
	execvp(argv[0],argv);&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2010.02.03&amp;diff=603</id>
		<title>ProvaPratica 2010.02.03</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2010.02.03&amp;diff=603"/>
		<updated>2014-04-28T13:57:43Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2010-02-03.pdf&amp;lt;/h1&amp;gt;   == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;  #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;sys/types.h&amp;gt; #include &amp;lt;dirent.h&amp;gt;...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2010-02-03.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int N_DIR1=0;&lt;br /&gt;
&lt;br /&gt;
void print_reverse(char**ptr)&lt;br /&gt;
{&lt;br /&gt;
	int i=0;&lt;br /&gt;
	for(i=N_DIR1-1;i&amp;gt;-1;i--)&lt;br /&gt;
		printf(&amp;quot;%s\n&amp;quot;,ptr[i]);&lt;br /&gt;
}&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
	int ris,i=0;&lt;br /&gt;
	char c;&lt;br /&gt;
	char*tmp;&lt;br /&gt;
	struct stat prova;&lt;br /&gt;
	char**filedir1=NULL;&lt;br /&gt;
	DIR *dp; &lt;br /&gt;
	struct dirent *ep; &lt;br /&gt;
	/*APERTURA DIRECTORY 1*/&lt;br /&gt;
	dp = opendir (&amp;quot;.&amp;quot;);&lt;br /&gt;
	if (dp != NULL)&lt;br /&gt;
	{&lt;br /&gt;
		while ((ep = readdir (dp))) /*Leggo i file nella directory*/&lt;br /&gt;
    	{&lt;br /&gt;
    		ris=lstat(ep-&amp;gt;d_name,&amp;amp;prova); /*Recupero le informazioni sul file*/&lt;br /&gt;
    		if (S_ISREG(prova.st_mode)) /*file regolare*/&lt;br /&gt;
    		{ &lt;br /&gt;
    		/*IL FILE E' UN ESEGUIBILE REGOLARE*/&lt;br /&gt;
    			N_DIR1++;&lt;br /&gt;
    			filedir1=(char**)realloc(filedir1,N_DIR1*sizeof(char*));&lt;br /&gt;
    			filedir1[N_DIR1-1]=ep-&amp;gt;d_name;&lt;br /&gt;
    		}&lt;br /&gt;
		}&lt;br /&gt;
		closedir (dp); /*ORA IN filedir1[] CI SONO TUTTI I FILE DELLA DIRECTORY 1*/&lt;br /&gt;
	}&lt;br /&gt;
	print_reverse(filedir1);&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
nota: non ho usato la qsort, ma ho semplicemente utilizzato il fatto che readdir() restituisce il contenuto in ordine alfabetico. E' corretto?&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2011.09.12&amp;diff=602</id>
		<title>ProvaPratica 2011.09.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2011.09.12&amp;diff=602"/>
		<updated>2014-04-28T13:54:26Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2011-09-12.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int N_DIR1=0,N_DIR2=0;&lt;br /&gt;
&lt;br /&gt;
int source(char*s)&lt;br /&gt;
{&lt;br /&gt;
	int x=strlen(s);&lt;br /&gt;
	if (x&amp;gt;=3)&lt;br /&gt;
	{&lt;br /&gt;
		if ((s[x-1]=='c') || (s[x-1]=='h'))&lt;br /&gt;
		{&lt;br /&gt;
			if (s[x-2]=='.') return 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
void print_diff(char**dir1,char**dir2)&lt;br /&gt;
{&lt;br /&gt;
	int i,j,found=0;&lt;br /&gt;
	for (i=0;i&amp;lt;N_DIR1;i++){&lt;br /&gt;
		for(j=0;j&amp;lt;N_DIR2;j++){&lt;br /&gt;
			if (!strcmp(dir1[i],dir2[j]))&lt;br /&gt;
				found=1;&lt;br /&gt;
			 }&lt;br /&gt;
			if (found!=1) &lt;br /&gt;
				printf(&amp;quot;%s presente solo nella directory 1\n&amp;quot;,dir1[i]);&lt;br /&gt;
			found=0;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	found=0;&lt;br /&gt;
	&lt;br /&gt;
	for (i=0;i&amp;lt;N_DIR2;i++)&lt;br /&gt;
	{&lt;br /&gt;
		for(j=0;j&amp;lt;N_DIR1;j++){&lt;br /&gt;
			if (!strcmp(dir2[i],dir1[j]))&lt;br /&gt;
				found=1;&lt;br /&gt;
			}&lt;br /&gt;
			if (found!=1)&lt;br /&gt;
				printf(&amp;quot;%s presente solo nella directory 2\n&amp;quot;,dir2[i]);&lt;br /&gt;
			found=0;&lt;br /&gt;
	}&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
int main (int argc,char*argv[])&lt;br /&gt;
{&lt;br /&gt;
	int ris,i=0;&lt;br /&gt;
	char c;&lt;br /&gt;
	char*tmp;&lt;br /&gt;
	struct stat prova;&lt;br /&gt;
	char**filedir1=NULL,**filedir2=NULL;&lt;br /&gt;
	DIR *dp,*dp2; &lt;br /&gt;
	struct dirent *ep;    &lt;br /&gt;
	if (argc!=3)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Usage: ./cmpsource.out DIR1 DIR2\n&amp;quot;);&lt;br /&gt;
		return(1);&lt;br /&gt;
	} &lt;br /&gt;
	/*APERTURA DIRECTORY 1*/&lt;br /&gt;
	dp = opendir (argv[1]);&lt;br /&gt;
	if (dp != NULL)&lt;br /&gt;
	{&lt;br /&gt;
		while ((ep = readdir (dp))) /*Leggo i file nella directory*/&lt;br /&gt;
    	{&lt;br /&gt;
    		ris=lstat(ep-&amp;gt;d_name,&amp;amp;prova); /*Recupero le informazioni sul file*/&lt;br /&gt;
    		if (S_ISREG(prova.st_mode)) /*file regolare*/&lt;br /&gt;
    		{ &lt;br /&gt;
    		/*IL FILE E' UN ESEGUIBILE REGOLARE*/&lt;br /&gt;
    			if (source(ep-&amp;gt;d_name)){ /*IL FILE E' UN SORGENTE (.c/.h)*/&lt;br /&gt;
    			N_DIR1++;&lt;br /&gt;
    			filedir1=(char**)realloc(filedir1,N_DIR1*sizeof(char*));&lt;br /&gt;
    			filedir1[N_DIR1-1]=ep-&amp;gt;d_name;&lt;br /&gt;
    			}&lt;br /&gt;
    		}&lt;br /&gt;
		}&lt;br /&gt;
		closedir (dp); /*ORA IN filedir1[] CI SONO TUTTI I FILE SORGENTE DELLA DIRECTORY 1*/&lt;br /&gt;
	}&lt;br /&gt;
	/*FINE LETTURA DIRECTORY 1*/&lt;br /&gt;
	/*APERTURA DIRECTORY 2*/&lt;br /&gt;
	dp2 = opendir (argv[2]);&lt;br /&gt;
	if (dp2 != NULL)&lt;br /&gt;
	{&lt;br /&gt;
		while ((ep = readdir (dp2))) /*Leggo i file nella directory*/&lt;br /&gt;
    	{&lt;br /&gt;
    		ris=lstat(ep-&amp;gt;d_name,&amp;amp;prova); /*Recupero le informazioni sul file*/&lt;br /&gt;
    		if (S_ISREG(prova.st_mode)) /*file regolare*/&lt;br /&gt;
    		{ &lt;br /&gt;
    		/*IL FILE E' UN ESEGUIBILE REGOLARE*/&lt;br /&gt;
    			if (source(ep-&amp;gt;d_name)){ /*IL FILE E' UN SORGENTE (.c/.h)*/&lt;br /&gt;
    			N_DIR2++;&lt;br /&gt;
    			filedir2=(char**)realloc(filedir2,N_DIR2*sizeof(char*));&lt;br /&gt;
    			filedir2[N_DIR2-1]=ep-&amp;gt;d_name;&lt;br /&gt;
    			}&lt;br /&gt;
    		}&lt;br /&gt;
		}&lt;br /&gt;
		closedir (dp); /*ORA IN filedir1[] CI SONO TUTTI I FILE SORGENTE DELLA DIRECTORY 1*/&lt;br /&gt;
	}&lt;br /&gt;
	/*FINE LETTURA DIRECTORY 2*/&lt;br /&gt;
	print_diff(filedir1,filedir2);&lt;br /&gt;
  	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2011.09.12&amp;diff=601</id>
		<title>ProvaPratica 2011.09.12</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2011.09.12&amp;diff=601"/>
		<updated>2014-04-28T13:53:55Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2011-09-12.pdf&amp;lt;/h1&amp;gt;   == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;sys/types.h&amp;gt; #include &amp;lt;dirent.h&amp;gt; ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2011-09-12.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int N_DIR1=0,N_DIR2=0;&lt;br /&gt;
&lt;br /&gt;
int source(char*s)&lt;br /&gt;
{&lt;br /&gt;
	int x=strlen(s);&lt;br /&gt;
	if (x&amp;gt;=3)&lt;br /&gt;
	{&lt;br /&gt;
		if ((s[x-1]=='c') || (s[x-1]=='h'))&lt;br /&gt;
		{&lt;br /&gt;
			if (s[x-2]=='.') return 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
void print_diff(char**dir1,char**dir2)&lt;br /&gt;
{&lt;br /&gt;
	int i,j,found=0;&lt;br /&gt;
	for (i=0;i&amp;lt;N_DIR1;i++){&lt;br /&gt;
		for(j=0;j&amp;lt;N_DIR2;j++){&lt;br /&gt;
			if (!strcmp(dir1[i],dir2[j]))&lt;br /&gt;
				found=1;&lt;br /&gt;
			 }&lt;br /&gt;
			if (found!=1) &lt;br /&gt;
				printf(&amp;quot;%s presente solo nella directory 1\n&amp;quot;,dir1[i]);&lt;br /&gt;
			found=0;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	found=0;&lt;br /&gt;
	&lt;br /&gt;
	for (i=0;i&amp;lt;N_DIR2;i++)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;SONO NEL FOR™\n&amp;quot;);&lt;br /&gt;
		for(j=0;j&amp;lt;N_DIR1;j++){&lt;br /&gt;
			if (!strcmp(dir2[i],dir1[j]))&lt;br /&gt;
				found=1;&lt;br /&gt;
			}&lt;br /&gt;
			if (found!=1)&lt;br /&gt;
				printf(&amp;quot;%s presente solo nella directory 2\n&amp;quot;,dir2[i]);&lt;br /&gt;
			found=0;&lt;br /&gt;
	}&lt;br /&gt;
	return;&lt;br /&gt;
}&lt;br /&gt;
int main (int argc,char*argv[])&lt;br /&gt;
{&lt;br /&gt;
	int ris,i=0;&lt;br /&gt;
	char c;&lt;br /&gt;
	char*tmp;&lt;br /&gt;
	struct stat prova;&lt;br /&gt;
	char**filedir1=NULL,**filedir2=NULL;&lt;br /&gt;
	DIR *dp,*dp2; &lt;br /&gt;
	struct dirent *ep;    &lt;br /&gt;
	if (argc!=3)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Usage: ./cmpsource.out DIR1 DIR2\n&amp;quot;);&lt;br /&gt;
		return(1);&lt;br /&gt;
	} &lt;br /&gt;
	/*APERTURA DIRECTORY 1*/&lt;br /&gt;
	dp = opendir (argv[1]);&lt;br /&gt;
	if (dp != NULL)&lt;br /&gt;
	{&lt;br /&gt;
		while ((ep = readdir (dp))) /*Leggo i file nella directory*/&lt;br /&gt;
    	{&lt;br /&gt;
    		ris=lstat(ep-&amp;gt;d_name,&amp;amp;prova); /*Recupero le informazioni sul file*/&lt;br /&gt;
    		if (S_ISREG(prova.st_mode)) /*file regolare*/&lt;br /&gt;
    		{ &lt;br /&gt;
    		/*IL FILE E' UN ESEGUIBILE REGOLARE*/&lt;br /&gt;
    			if (source(ep-&amp;gt;d_name)){ /*IL FILE E' UN SORGENTE (.c/.h)*/&lt;br /&gt;
    			N_DIR1++;&lt;br /&gt;
    			filedir1=(char**)realloc(filedir1,N_DIR1*sizeof(char*));&lt;br /&gt;
    			filedir1[N_DIR1-1]=ep-&amp;gt;d_name;&lt;br /&gt;
    			}&lt;br /&gt;
    		}&lt;br /&gt;
		}&lt;br /&gt;
		closedir (dp); /*ORA IN filedir1[] CI SONO TUTTI I FILE SORGENTE DELLA DIRECTORY 1*/&lt;br /&gt;
	}&lt;br /&gt;
	/*FINE LETTURA DIRECTORY 1*/&lt;br /&gt;
	/*APERTURA DIRECTORY 2*/&lt;br /&gt;
	dp2 = opendir (argv[2]);&lt;br /&gt;
	if (dp2 != NULL)&lt;br /&gt;
	{&lt;br /&gt;
		while ((ep = readdir (dp2))) /*Leggo i file nella directory*/&lt;br /&gt;
    	{&lt;br /&gt;
    		ris=lstat(ep-&amp;gt;d_name,&amp;amp;prova); /*Recupero le informazioni sul file*/&lt;br /&gt;
    		if (S_ISREG(prova.st_mode)) /*file regolare*/&lt;br /&gt;
    		{ &lt;br /&gt;
    		/*IL FILE E' UN ESEGUIBILE REGOLARE*/&lt;br /&gt;
    			if (source(ep-&amp;gt;d_name)){ /*IL FILE E' UN SORGENTE (.c/.h)*/&lt;br /&gt;
    			N_DIR2++;&lt;br /&gt;
    			filedir2=(char**)realloc(filedir2,N_DIR2*sizeof(char*));&lt;br /&gt;
    			filedir2[N_DIR2-1]=ep-&amp;gt;d_name;&lt;br /&gt;
    			}&lt;br /&gt;
    		}&lt;br /&gt;
		}&lt;br /&gt;
		closedir (dp); /*ORA IN filedir1[] CI SONO TUTTI I FILE SORGENTE DELLA DIRECTORY 1*/&lt;br /&gt;
	}&lt;br /&gt;
	/*FINE LETTURA DIRECTORY 2*/&lt;br /&gt;
	print_diff(filedir1,filedir2);&lt;br /&gt;
  	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=528</id>
		<title>ProvaTeorica 2012.07.16</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=528"/>
		<updated>2014-03-30T22:34:50Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.cs.unibo.it/~renzo/so/compiti/2012-07-16.tot.pdf Link Testo]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Esercizio C.1&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define RED 0&lt;br /&gt;
#define BLUE 1&lt;br /&gt;
//restituisce 1 se c'e piu del 75% blue o 75% di red&lt;br /&gt;
//restituisce 0 se non c'e una maggiornza&lt;br /&gt;
int media(color){&lt;br /&gt;
	int mediared;&lt;br /&gt;
	int localinto =  into;&lt;br /&gt;
	if (color != NULL){&lt;br /&gt;
		localinto[color]++;&lt;br /&gt;
	}&lt;br /&gt;
	mediared = ((100*localinto[0])/(localinto[0]+localinto[1]));&lt;br /&gt;
	if(mediared &amp;gt;=75 || mediared &amp;lt; 25){&lt;br /&gt;
		return 1;//75% di rossi o di blue&lt;br /&gt;
	}else{&lt;br /&gt;
		return 0;// non c'e maggioranza		&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
&lt;br /&gt;
	conditon oktoenter[2];&lt;br /&gt;
	int into[2];&lt;br /&gt;
&lt;br /&gt;
	enter(color){&lt;br /&gt;
		if(media(color) != 1){// attendo perche' non c'e una maggioranza&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		}&lt;br /&gt;
		into[color]++;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	exit(color){&lt;br /&gt;
		into[color]--;&lt;br /&gt;
		if(media(1-color) == 1){&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
		}else if(media(color) == 1){&lt;br /&gt;
			oktoenter[color].signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define ROSSO 0&lt;br /&gt;
#define BLU 1&lt;br /&gt;
&lt;br /&gt;
monitor limcol {&lt;br /&gt;
	condition oktoenter&lt;br /&gt;
	condition oktoexit&lt;br /&gt;
	int running[2] // numero di processi rossi [0] e blu [1] in esecuzione&lt;br /&gt;
	queue waiting /* coda delle coppie (colore,azione) dei processi in attesa di entrare (azione==1)&lt;br /&gt;
			 o uscire (azione==-1) */&lt;br /&gt;
	&lt;br /&gt;
	/* restituisce true se aggiungendo o rimuovendo (in base a i) un processo del colore passato&lt;br /&gt;
	viene rispettato il 75% dei processi di un colore */&lt;br /&gt;
	bool morethan75p(colore, int i) { &lt;br /&gt;
		return (running[colore]+i&amp;gt;=running[1-colore]*3 || (running[colore]+i)*3&amp;lt;=running[1-colore])&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	// risveglia il processo in testa alla coda waiting se è possibile farlo&lt;br /&gt;
	void checkwakeup() {&lt;br /&gt;
		if (waiting.empty() == false) {&lt;br /&gt;
			colore,azione = waiting.head() // head resituisce l'elemento in testa senza rimuoverlo&lt;br /&gt;
			if (morethan75p(colore,azione)) {&lt;br /&gt;
				waiting.dequeue()&lt;br /&gt;
				if (azione == 1)&lt;br /&gt;
					oktoenter.signal()&lt;br /&gt;
				else&lt;br /&gt;
					oktoexit.signal()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
 &lt;br /&gt;
	procedure entry enter(colore) {&lt;br /&gt;
		if (morethan75p(colore,1)==false) {&lt;br /&gt;
			waiting.enqueue(colore,1)&lt;br /&gt;
			oktoenter.wait()&lt;br /&gt;
		}&lt;br /&gt;
		running[colore]++&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
 &lt;br /&gt;
	procedure entry exit(colore) {&lt;br /&gt;
		if (morethan75p(colore,-1)==false) {&lt;br /&gt;
			waiting.enqueue(colore,-1)&lt;br /&gt;
			oktoexit.wait()&lt;br /&gt;
		}&lt;br /&gt;
		running[colore]--&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Daniele Cortesi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLUE 1&lt;br /&gt;
int majorcolor = -1&lt;br /&gt;
int numproc[2] = 0,0&lt;br /&gt;
cond oktoenter[2]  //bastavano due condizioni.&lt;br /&gt;
cond oktoexit[2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
	procedure entry enter(COL){&lt;br /&gt;
		if(COL == majorcolor){&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			if((proc[majorcolor]*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;lt; 75)&lt;br /&gt;
				oktoenter[COL].wait()&lt;br /&gt;
			if(majorcolor == -1)&lt;br /&gt;
				majorcolor == COL&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			majorcolor = COL&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(COL){&lt;br /&gt;
		if(numproc[COL] + numproc[1-COL] == 1){&lt;br /&gt;
			majorcolor = -1&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == majorcolor){&lt;br /&gt;
			if(((proc[majorcolor] - 1)*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;lt; 75){&lt;br /&gt;
				oktoexit[COL].wait()&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoexit[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLU 1&lt;br /&gt;
&lt;br /&gt;
limcol{&lt;br /&gt;
	/*variable*/&lt;br /&gt;
	int array[2] = 0,0;&lt;br /&gt;
	color major = -1;&lt;br /&gt;
	/*condition*/&lt;br /&gt;
	condition oktoenter[2];&lt;br /&gt;
	condition oktoleave[2];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter( color ){&lt;br /&gt;
		if ( majorcolor == -1 ) &lt;br /&gt;
			majorcolor = color;&lt;br /&gt;
		if ( majorcolor == (1-color) &amp;amp;&amp;amp; newmajorcolor%(color) &amp;lt; 75% )&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		array[color]++; &lt;br /&gt;
		if ( majorcolor == -1 )            //se un processo si risveglia nel monitor vuoto deve impostare majorcolor&lt;br /&gt;
			majorcolor = color;&lt;br /&gt;
		if ( newmajorcolor%(1-color) &amp;gt;= 75% )         &lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
					}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit( color ){&lt;br /&gt;
		if ( majorcolor == color &amp;amp;&amp;amp; majorcolor_less1%(color) &amp;gt; 75% )&lt;br /&gt;
			oktoleave[color].wait();&lt;br /&gt;
		array[color]--;&lt;br /&gt;
		if ( !colorsempty() )&lt;br /&gt;
			if ( majorcolor_less1%(color) &amp;gt;= 75% )&lt;br /&gt;
				oktoleave[1-color].signal();&lt;br /&gt;
		else{&lt;br /&gt;
			majorcolor == -1;&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
				}&lt;br /&gt;
					}	 &lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
newmajorcolor%(color) calcola la nuova % del colore maggiore aggiungendo color&lt;br /&gt;
majorcolor_less1%(color) calcola la nuova % del colore maggiore togliendo color&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Pir@t@&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#DEFINE BLUE 0&lt;br /&gt;
#DEFINE RED 1&lt;br /&gt;
monitor limcol{&lt;br /&gt;
condition ok;&lt;br /&gt;
int numcolor[2];&lt;br /&gt;
Queue q;&lt;br /&gt;
int i=1;&lt;br /&gt;
procedure entry enter(color){&lt;br /&gt;
if((numcolor[color] + 1 &amp;lt; float((tot+1)*(75/100))  &amp;amp;&amp;amp;&lt;br /&gt;
   numcolor[color] + 1 &amp;gt;= float((tot+1)*(25/100))) ||&lt;br /&gt;
   !q.empty() ) &lt;br /&gt;
	{&lt;br /&gt;
	q.enqueue(color);&lt;br /&gt;
	ok.wait();&lt;br /&gt;
	i++;&lt;br /&gt;
	if(!q.empty()){&lt;br /&gt;
          if(numcolor[q.head()] + i &amp;gt;= float((tot+i)*(75/100)) ||&lt;br /&gt;
	   numcolor[q.head()] + i &amp;lt; float((tot+i)*(25/100)))  )&lt;br /&gt;
	{&lt;br /&gt;
	q.dequeue();&lt;br /&gt;
	ok.signal();&lt;br /&gt;
	}&lt;br /&gt;
	i=1;&lt;br /&gt;
	}&lt;br /&gt;
	}&lt;br /&gt;
numcolor[color]++;&lt;br /&gt;
tot++;&lt;br /&gt;
}&lt;br /&gt;
procedure entry exit(color){&lt;br /&gt;
numcolor[color]--;&lt;br /&gt;
tot--;&lt;br /&gt;
if( numcolor[q.head()] + 1 &amp;gt;= float((tot+1)*(75/100))  ||&lt;br /&gt;
    numcolor[q.head()] + 1 &amp;lt; float((tot+1)*(25/100)) )&lt;br /&gt;
  	{&lt;br /&gt;
	q.dequeue();&lt;br /&gt;
	ok.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Alessandro&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define LIMIT 0.75&lt;br /&gt;
#define RED 0&lt;br /&gt;
#define BLUE 1&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
	double procNum; // numero processi all'interno del semaforo&lt;br /&gt;
	double pColourNum[2]; // numero di processi rossi [0] o blu [1]&lt;br /&gt;
	condition okToEnter;&lt;br /&gt;
	condition okToLeave;&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter(colour)&lt;br /&gt;
	{	// Se ci sono processi nel semaforo &amp;amp;&amp;amp; il numero dei processi del colore attuale è inferiore &lt;br /&gt;
                // al 75% &amp;amp;&amp;amp; il numero dei processi dell'altro colore è inferiore al 75% sul totale+1, wait&lt;br /&gt;
		if(procNum != 0 &amp;amp;&amp;amp; (pColourNum[1-colour]/procNum+1) &amp;lt; LIMIT &amp;amp;&amp;amp; (pColourNum[colour]/procNum) &amp;lt; LIMIT)&lt;br /&gt;
		{&lt;br /&gt;
			okToEnter.wait();&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			procNum++;&lt;br /&gt;
			pColourNum[colour]++;&lt;br /&gt;
&lt;br /&gt;
			// Se qualcuno è in attesa di uscire e adesso le percentuali lo permettono, signal&lt;br /&gt;
			if((pColourNum[colour]/procNum-1) &amp;gt;= LIMIT)&lt;br /&gt;
			{&lt;br /&gt;
				okToLeave.signal();&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			// Se qualcuno è in attesa di entrare e adesso le percentuali lo permettono, signal&lt;br /&gt;
			if((pColourNum[colour]/procNum+1) &amp;gt;= LIMIT)&lt;br /&gt;
			{&lt;br /&gt;
				okToEnter.signal();&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(colour)&lt;br /&gt;
	{&lt;br /&gt;
		// Se il numero di processi del colore attuale è inferiore al 75% sul totale+1, wait&lt;br /&gt;
		if((pColourNum[colour]/procNum-1) &amp;lt; LIMIT)&lt;br /&gt;
		{&lt;br /&gt;
			okToLeave.wait();&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			procNum--;&lt;br /&gt;
			pColourNum[colour]--;&lt;br /&gt;
&lt;br /&gt;
			// Se qualcuno dell'altro colore è in attesa di uscire e adesso le percentuali lo permettono, signal&lt;br /&gt;
                        if((pColourNum[1-colour]/procNum-1) &amp;gt;= LIMIT)&lt;br /&gt;
                        {&lt;br /&gt;
                                okToLeave.signal();&lt;br /&gt;
                        }&lt;br /&gt;
&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	limcol&lt;br /&gt;
	{&lt;br /&gt;
		procNum = 0;&lt;br /&gt;
		pColourNum[0] = 0;&lt;br /&gt;
		pColourNum[1] = 0;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Mirko&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#DEFINE RED 0&lt;br /&gt;
#DEFINE BLUE 1&lt;br /&gt;
&lt;br /&gt;
int is_ok(int n_red,int n_blue); /*funzione is_ok: restituisce 1 se la configurazione passata in input è accettabile*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor limcol&lt;br /&gt;
{&lt;br /&gt;
	int number[2]; /*number[i] contiene il numero di processi del colore i nella sezione limcol*/&lt;br /&gt;
	condition oktoenter[2],oktoexit[2];&lt;br /&gt;
	procedure entry enter(int colour)&lt;br /&gt;
	{&lt;br /&gt;
		if (!is_ok(number[colour]+1,number[!colour]))&lt;br /&gt;
			oktoenter[colour].wait();&lt;br /&gt;
		number[colour]++;&lt;br /&gt;
		if (is_ok(number[colour]+1,number[!colour]))&lt;br /&gt;
			oktoenter[colour].signal();&lt;br /&gt;
		if (is_ok(number[colour],number[!colour]+1))&lt;br /&gt;
			oktoenter[!colour].signal();&lt;br /&gt;
		if (is_ok(number[colour]-1,number[!colour]))&lt;br /&gt;
			oktoexit[colour].signal();&lt;br /&gt;
		if (is_ok(number[colour],number[!colour]-1))&lt;br /&gt;
			oktoexit[!colour].signal();&lt;br /&gt;
	}&lt;br /&gt;
			&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry exit(int colour)&lt;br /&gt;
	{&lt;br /&gt;
		if (!is_ok(number[colour]-1,number[!colour]))&lt;br /&gt;
			oktoexit[colour].wait(); &lt;br /&gt;
		number[colour]--;&lt;br /&gt;
		if (is_ok(number[colour]+1,number[!colour]))&lt;br /&gt;
			oktoenter[colour].signal();&lt;br /&gt;
		if (is_ok(number[colour],number[!colour]+1))&lt;br /&gt;
			oktoenter[!colour].signal();&lt;br /&gt;
		if (is_ok(number[colour]-1,number[!colour]))&lt;br /&gt;
			oktoexit[colour].signal();&lt;br /&gt;
		if (is_ok(number[colour],number[!colour]-1))&lt;br /&gt;
			oktoexit[!colour].signal();&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Stefano&lt;br /&gt;
&lt;br /&gt;
==Esercizio c.2==&lt;br /&gt;
Per quali indici n le funzioni foo possono essere utilizzate al posto della test&amp;amp;set?&lt;br /&gt;
&lt;br /&gt;
Risposta: per n = 5&lt;br /&gt;
&lt;br /&gt;
Nella Test&amp;amp;Set x prende il valore di y, quindi y deve essere = booln(x,y)&lt;br /&gt;
Andiamo a vedere per quali valori y è uguale a booln(x,y)&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! x || y || bool0 || bool1 || bool2 || bool3 || bool4 || bool5 || bool6 || bool7 || bool8 || bool9 || bool10 || bool11 || bool12 || bool13 || bool14 || bool15&lt;br /&gt;
|-&lt;br /&gt;
| 0 || '''0''' || '''0''' || '''0''' || '''0''' || '''0''' || '''0''' || '''0''' || '''0''' || '''0''' || 1 || 1 || 1 || 1 || 1 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || '''1''' || 0 || 0 || 0 || 0 || '''1''' || '''1''' || '''1''' || '''1''' || 0 || 0 || 0 || 0 || '''1''' || '''1''' || '''1''' || '''1'''&lt;br /&gt;
|-&lt;br /&gt;
| 1 || '''0''' || '''0''' || '''0''' || 1 || 1 || '''0''' || '''0''' || 1 || 1 || '''0''' || '''0''' || 1 || 1 || '''0''' || '''0''' || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || '''1''' || 0 || '''1''' || 0 || '''1''' || 0 || '''1''' || 0 || '''1''' || 0 || '''1''' || 0 || '''1''' || 0 || '''1''' || 0 || '''1'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In bold sono indicati i valori per cui y = booln(x,y)&lt;br /&gt;
L'unico caso in cui i valori sono evidenziati in ogni riga è per bool5.&lt;br /&gt;
&lt;br /&gt;
Giulia (non sono molto sicura della soluzione, ma questo è il ragionamento che mi è sembrato più corretto)&lt;br /&gt;
&lt;br /&gt;
==Esercizio g.1==&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Reference String&lt;br /&gt;
| 1 || 2 || 3 || 4 || 5 || 6 || 4 || 5 || 6 || 3 || 2 || 1 || 3 || 2 || 1 || 6 || 5 || 4 || 6 || 5 || 4 || 1 || 2 || 3&lt;br /&gt;
|-&lt;br /&gt;
! Page Frame 1&lt;br /&gt;
| 1 || 1 || 1 || 4 || 4 || 4 ||   ||   ||   || 3 || 3 || 3 ||   ||   ||   || 6 || 6 || 6 ||   ||   ||   || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! Page Frame 2&lt;br /&gt;
|   || 2 || 2 || 2 || 5 || 5 ||   ||   ||   || 5 || 2 || 2 ||   ||   ||   || 2 || 5 || 5 ||   ||   ||   || 5 || 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
! Page Frame 3&lt;br /&gt;
|   ||   || 3 || 3 || 3 || 6 ||   ||   ||   || 6 || 6 || 1 ||   ||   ||   || 1 || 1 || 4 ||   ||   ||   || 4 || 4 || 3&lt;br /&gt;
|}&lt;br /&gt;
                        &lt;br /&gt;
The above Reference String is both FIFO, LRU and MIN compliant.&lt;br /&gt;
&lt;br /&gt;
-TomOgn&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.01.24&amp;diff=476</id>
		<title>ProvaTeorica 2013.01.24</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.01.24&amp;diff=476"/>
		<updated>2014-03-19T14:16:01Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Esercizio C1:&lt;br /&gt;
(a) Scrivere un monitor nmbb che realizzi un buffer limitato (di ampiezza BUFSIZE) che consenta alle&lt;br /&gt;
chiamate write (inserimento nel buffer) e read (lettura da buffer) di operare su vettori di piu' elementi. In particolare&lt;br /&gt;
l'interfaccia delle procedure entry da implementare e' la seguente:&lt;br /&gt;
procedure entry write(int n, struct elem *v);&lt;br /&gt;
procedure entry read(int m, struct elem *w);&lt;br /&gt;
se n o m sono maggiori di BUFSIZE le funzioni non devono fare nulla (caso di errore).&lt;br /&gt;
La funzione write deve attendere che ci sia spazio nel buffer per inserire n elementi (il vettore v conterra' n elementi).&lt;br /&gt;
Solo quando e' possibile completare l'operazione vengono inseriti tutti gli elementi di v nel buffer.&lt;br /&gt;
La funzione read attende che vi siano almeno m elementi nel buffer quindi estrae dal buffer (in ordine FIFO) m elementi e li copia nel vettore w .&lt;br /&gt;
(b) sono possibili casi di deadlock? (motivare dettagliatamente la risposta)&lt;br /&gt;
&lt;br /&gt;
La mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
read(): legge dalla coda un elemento senza rimuoverlo&lt;br /&gt;
queue(elem v,int n): inserisce nella coda n elementi v;&lt;br /&gt;
dequeue(int n): legge n elementi dalla coda e li rimuove;&lt;br /&gt;
&lt;br /&gt;
monitor  mnbb{&lt;br /&gt;
	conditon oktowrite, oktoread;&lt;br /&gt;
	queue qwrite,qread;&lt;br /&gt;
&lt;br /&gt;
	procedure entry write(int n, struct elem *v){&lt;br /&gt;
		if(n &amp;gt; BUFSIZE){&lt;br /&gt;
			return(ERROR);&lt;br /&gt;
		}&lt;br /&gt;
		if( n &amp;gt; (BUFSIZE - buff.lengh)){&lt;br /&gt;
			qwrite.queue( n, 1 );&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		}&lt;br /&gt;
		buff.queue( v, n );&lt;br /&gt;
		if(qread.read() &amp;lt;= buff.lengh){&lt;br /&gt;
			qread.dequeue(1);&lt;br /&gt;
			oktoread.signal();&lt;br /&gt;
		}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
	procedure entry read(int m, struct elem *w){&lt;br /&gt;
		if(m &amp;gt; BUFSIZE){&lt;br /&gt;
			return(ERROR);&lt;br /&gt;
		} &lt;br /&gt;
		if(m &amp;gt; buff.lengh){&lt;br /&gt;
			qread.queue( m, 1 );&lt;br /&gt;
			oktoread.wait();&lt;br /&gt;
		}&lt;br /&gt;
		w = buff.dequeue(m);&lt;br /&gt;
		if(qwrite.read() &amp;lt;= (BUFSIZE - buff.lengh)){&lt;br /&gt;
			qwrite.dequeue(1);&lt;br /&gt;
			oktowirte.signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor nmbb{&lt;br /&gt;
	queue buffer;&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktoread;&lt;br /&gt;
	&lt;br /&gt;
	/* assumiamo che essendo un buffer limitato ci sia un solo processo che vuole scrivere e un solo processo che vuole leggere */&lt;br /&gt;
	int N, M;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry write(int n, struct elem *v){&lt;br /&gt;
		if(n&amp;gt;BUFSIZE) return;&lt;br /&gt;
		N=n;&lt;br /&gt;
		if((BUFSIZE - buffer.len) &amp;lt; N)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		&lt;br /&gt;
		for(i=0; i&amp;lt;N; i++)&lt;br /&gt;
			buffer.enqueue(v[i]);&lt;br /&gt;
			&lt;br /&gt;
		if(buffer.len &amp;gt;= M)&lt;br /&gt;
			oktoread.signal();&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
	procedure entry read(int m, struct elem *w){&lt;br /&gt;
		if(m&amp;gt;BUFSIZE) return;&lt;br /&gt;
		M=m;&lt;br /&gt;
		if((BUFSIZE - buffer.len) &amp;lt; M)&lt;br /&gt;
			oktoread.wait();&lt;br /&gt;
		&lt;br /&gt;
		for(i=0; i&amp;lt;M; i++)&lt;br /&gt;
			w[i] = buffer.dequeue;&lt;br /&gt;
		&lt;br /&gt;
		if((BUFSIZE - buffer.len) &amp;gt;= N)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Si può verificare deadlock. Esempio: un lettore vuole leggere un tot di elementi, ma quelli presenti non sono sufficienti. Uno scrittore a sua volta non può più scrivere un certo numero di elementi in quanto il buffer è parzialmente occupato. Lo scrittore aspetterà che il lettore legga; il lettore aspetterà invece lo scrittore: deadlock.&lt;br /&gt;
&lt;br /&gt;
L'eventualità che si verifichi deadlock tuttavia è contemplata dalla traccia, come fa capire il punto b)&lt;br /&gt;
&lt;br /&gt;
Gabriele e Giulia&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.07.19&amp;diff=475</id>
		<title>ProvaTeorica 2013.07.19</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.07.19&amp;diff=475"/>
		<updated>2014-03-19T14:05:31Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Esecizio C1:&lt;br /&gt;
scrivere un monitor m vie che gestisca M buffer limitati. Ogni buffer ha l'ampiezza di M ELEM elementi. I produttori chiamano la procedure entry:&lt;br /&gt;
put(generic *object)&lt;br /&gt;
mentre i consumatori chiamano la procedure entry&lt;br /&gt;
generic *get(int n)&lt;br /&gt;
I produttori conferiscono un vettore di M element i, uno per ogni buffer al buffer.&lt;br /&gt;
Per esempio put( v ), (dove v e' un vettore di M elementi) inserisce ogni elemento del vettore nel buffer corrispondente.&lt;br /&gt;
I consumatori ricevono un oggetto dal buffer indicato come parametro oggetti ma attendono sempre che ci sia almeno un elemento in ogni buffer.&lt;br /&gt;
&lt;br /&gt;
Mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*AreEmpy: */&lt;br /&gt;
/*true quando almeno un buff é vuoto*/&lt;br /&gt;
/*false quando tutti hanno almeno un elemento*/&lt;br /&gt;
bool areEmpy(*buff){&lt;br /&gt;
	for(int a = 0; a&amp;lt;M;a++){&lt;br /&gt;
		if(buff[a].lengh != 0){&lt;br /&gt;
			return true;&lt;br /&gt;
		}&lt;br /&gt;
        }&lt;br /&gt;
	return false;&lt;br /&gt;
}&lt;br /&gt;
/*AreFull: */&lt;br /&gt;
/*true quando almeno un buff é pieno*/&lt;br /&gt;
/*false quando sono tutti non pieni*/&lt;br /&gt;
bool areFull(*buff){&lt;br /&gt;
	for(int a =  0; a&amp;lt;M;a++){&lt;br /&gt;
		if (buff[a].lengh == MELEM){&lt;br /&gt;
			return true;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return false;   &lt;br /&gt;
}&lt;br /&gt;
monitor mvie{&lt;br /&gt;
	put(generic *object){&lt;br /&gt;
		if( areFull(buff) ) &lt;br /&gt;
			oktoput.wait();&lt;br /&gt;
		for(int a = 0; a&amp;lt;M;a++){&lt;br /&gt;
			buf[a].queue(object[a]);&lt;br /&gt;
		}&lt;br /&gt;
		for(int a = 0; a&amp;lt;M;a++){&lt;br /&gt;
			oktoget[a].signal();//tutti i buffer hanno almeno un elemento quindi manda la signal a tutti i lettori&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	generic *get(int i){&lt;br /&gt;
		if( areEmpty(buff))&lt;br /&gt;
			oktoget.wait();&lt;br /&gt;
		buf[i].dequeue(); &lt;br /&gt;
		if(!areFull(buf)) //  se cé spazio in tutti i buffer manda la signal per scrivere&lt;br /&gt;
			oktoput.signal(); &lt;br /&gt;
    	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia soluzione:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int everything_set(queue[]) /*prende un array di code e ritorna 1 se sono tutte non vuote*/&lt;br /&gt;
int not_full(queue[]) /*prende un array di code e ritorna 1 se tutte le code hanno meno di MELEM elementi*/&lt;br /&gt;
&lt;br /&gt;
monitor mvie&lt;br /&gt;
{&lt;br /&gt;
	queue buf[M];&lt;br /&gt;
	condition oktowrite,oktoread;&lt;br /&gt;
	procedure entry put(generic *object)&lt;br /&gt;
	{&lt;br /&gt;
		if (!not_full(buf))&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		for (i=0;i&amp;lt;M;i++)&lt;br /&gt;
		{&lt;br /&gt;
			buf[i].enqueue(object[i]);&lt;br /&gt;
		}&lt;br /&gt;
		oktoread.signal();&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry generic* get (int n)&lt;br /&gt;
	{&lt;br /&gt;
		if (!everything_set(buf))&lt;br /&gt;
			oktoread.wait();&lt;br /&gt;
		generic g=buf[n].dequeue();&lt;br /&gt;
		if (not_full(buf)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Secondo me, bloccare il processo che vuole fare PUT, nel caso in cui esiste un buffer pieno, determina DEADLOCK.&lt;br /&gt;
&lt;br /&gt;
Infatti il testo non lo chiede. Faccio un esempio:&lt;br /&gt;
&lt;br /&gt;
Buffer 1: (empty)&lt;br /&gt;
&lt;br /&gt;
Buffer 2: (full)&lt;br /&gt;
&lt;br /&gt;
Processo 1: GET -&amp;gt; si blocca in quanto il Buffer 1 e' vuoto.&lt;br /&gt;
&lt;br /&gt;
Processo 2: PUT -&amp;gt; si blocca in quanto il Buffer 2 e' pieno.&lt;br /&gt;
&lt;br /&gt;
...etc...&lt;br /&gt;
&lt;br /&gt;
DEADLOCK&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Quando aggiungi a tutti e togli a 1 solo, e' plausibile che si formi, prima o poi, la situazione descritta sopra: un buffer pieno e uno vuoto.&lt;br /&gt;
Nella mia soluzione quindi non c'e' questo controllo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor mvie&lt;br /&gt;
{&lt;br /&gt;
	condition okP, okG;&lt;br /&gt;
	queue buf[M];&lt;br /&gt;
	&lt;br /&gt;
	bool isOneEmpty()&lt;br /&gt;
	{&lt;br /&gt;
		for (int i = 0; i &amp;lt; M; i++)&lt;br /&gt;
			if (buf[i].isEmpty())&lt;br /&gt;
				return true;&lt;br /&gt;
				&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry put(generic *object)&lt;br /&gt;
	{&lt;br /&gt;
		for (int i = 0; i &amp;lt; M; i++)&lt;br /&gt;
			if (buf[i].length() &amp;lt; MELEM)&lt;br /&gt;
				buf[i].enqueue(object[i]);&lt;br /&gt;
		&lt;br /&gt;
		okG.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry generic *get(int n)&lt;br /&gt;
	{&lt;br /&gt;
		if (isOneEmpty())&lt;br /&gt;
			okG.wait();&lt;br /&gt;
		&lt;br /&gt;
		return buf[n].dequeue();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-TomOgn&lt;br /&gt;
&lt;br /&gt;
uhm...per l'idea di buffer come l'abbiamo sempre visto mi sembra strano che una put su un buffer pieno vada &amp;quot;buttata&amp;quot;...&lt;br /&gt;
d'altronde anche quello che dici tu è vero, ponendo attesa in caso di buffer pieno si provoca indubbiamente deadlock XD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
monitor mvie{&lt;br /&gt;
	queue buffer[M];&lt;br /&gt;
	condition oktoput;&lt;br /&gt;
	condition oktoget;&lt;br /&gt;
	&lt;br /&gt;
	mvie(){&lt;br /&gt;
		int i;&lt;br /&gt;
		for(i=0; i&amp;lt;M; i++)&lt;br /&gt;
			buffer[i] = new queue(MELEM);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
	put(generic *object){&lt;br /&gt;
		int i;&lt;br /&gt;
		boolean b=1;&lt;br /&gt;
		for(i=0; i&amp;lt;M; i++){&lt;br /&gt;
			if(!(buffer[i].len &amp;lt; MELEM))&lt;br /&gt;
				b=0;&lt;br /&gt;
			}&lt;br /&gt;
		if(b == 0) /*almeno un elemento non era disponibile*/&lt;br /&gt;
			oktoput.wait();&lt;br /&gt;
		&lt;br /&gt;
		for(i=0; i&amp;lt;M; i++)&lt;br /&gt;
			buffer[i].enqueue(object[i]);&lt;br /&gt;
		oktoget.signal();&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
	generic *get(int n){&lt;br /&gt;
		int i;&lt;br /&gt;
		boolean b=1;&lt;br /&gt;
		for(i=0; i&amp;lt;M; i++){&lt;br /&gt;
			if(buffer[i].len == 0)&lt;br /&gt;
				b=0;&lt;br /&gt;
			}&lt;br /&gt;
		if(b == 0)&lt;br /&gt;
			oktoget.wait();&lt;br /&gt;
		&lt;br /&gt;
		object toread = buffer[n].dequeue;&lt;br /&gt;
		/* dobbiamo controllare che ci sia almeno un elemento libero per ciascun buffer prima di fare la signal */&lt;br /&gt;
		b = 1;&lt;br /&gt;
		for(i=0; i&amp;lt;M; i++){&lt;br /&gt;
			if(!(buffer[i].len &amp;lt; MELEM))&lt;br /&gt;
				b=0;&lt;br /&gt;
			}&lt;br /&gt;
		if(b)&lt;br /&gt;
			oktoput.signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Gabriele e Giulia&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.07.19&amp;diff=463</id>
		<title>ProvaTeorica 2013.07.19</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.07.19&amp;diff=463"/>
		<updated>2014-03-18T12:02:43Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Esecizio C1:&lt;br /&gt;
scrivere un monitor m vie che gestisca M buffer limitati. Ogni buffer ha l'ampiezza di M ELEM elementi. I produttori chiamano la procedure entry:&lt;br /&gt;
put(generic *object)&lt;br /&gt;
mentre i consumatori chiamano la procedure entry&lt;br /&gt;
generic *get(int n)&lt;br /&gt;
I produttori conferiscono un vettore di M element i, uno per ogni buffer al buffer.&lt;br /&gt;
Per esempio put( v ), (dove v e' un vettore di M elementi) inserisce ogni elemento del vettore nel buffer corrispondente.&lt;br /&gt;
I consumatori ricevono un oggetto dal buffer indicato come parametro oggetti ma attendono sempre che ci sia almeno un elemento in ogni buffer.&lt;br /&gt;
&lt;br /&gt;
Mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*AreEmpy: */&lt;br /&gt;
/*true quando almeno un buff é vuoto*/&lt;br /&gt;
/*false quando tutti hanno almeno un elemento*/&lt;br /&gt;
bool areEmpy(*buff){&lt;br /&gt;
	for(int a = 0; a&amp;lt;M;a++){&lt;br /&gt;
		if(buff[a].lengh != 0){&lt;br /&gt;
			return true;&lt;br /&gt;
		}&lt;br /&gt;
        }&lt;br /&gt;
	return false;&lt;br /&gt;
}&lt;br /&gt;
/*AreFull: */&lt;br /&gt;
/*true quando almeno un buff é pieno*/&lt;br /&gt;
/*false quando sono tutti non pieni*/&lt;br /&gt;
bool areFull(*buff){&lt;br /&gt;
	for(int a =  0; a&amp;lt;M;a++){&lt;br /&gt;
		if (buff[a].lengh == MELEM){&lt;br /&gt;
			return true;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return false;   &lt;br /&gt;
}&lt;br /&gt;
monitor mvie{&lt;br /&gt;
	put(generic *object){&lt;br /&gt;
		if( areFull(buff) ) &lt;br /&gt;
			oktoput.wait();&lt;br /&gt;
		for(int a = 0; a&amp;lt;M;a++){&lt;br /&gt;
			buf[a].queue(object[a]);&lt;br /&gt;
		}&lt;br /&gt;
		for(int a = 0; a&amp;lt;M;a++){&lt;br /&gt;
			oktoget[a].signal();//tutti i buffer hanno almeno un elemento quindi manda la signal a tutti i lettori&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	generic *get(int i){&lt;br /&gt;
		if( areEmpty(buff))&lt;br /&gt;
			oktoget.wait();&lt;br /&gt;
		buf[i].dequeue(); &lt;br /&gt;
		if(!areFull(buf)) //  se cé spazio in tutti i buffer manda la signal per scrivere&lt;br /&gt;
			oktoput.signal(); &lt;br /&gt;
    	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia soluzione:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int everything_set(queue[]) /*prende un array di code e ritorna 1 se sono tutte non vuote*/&lt;br /&gt;
int not_full(queue[]) /*prende un array di code e ritorna 1 se tutte le code hanno meno di MELEM elementi*/&lt;br /&gt;
&lt;br /&gt;
monitor mvie&lt;br /&gt;
{&lt;br /&gt;
	queue buf[M];&lt;br /&gt;
	condition oktowrite,oktoread;&lt;br /&gt;
	procedure entry put(generic *object)&lt;br /&gt;
	{&lt;br /&gt;
		if (!not_full(buf))&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
		for (i=0;i&amp;lt;M;i++)&lt;br /&gt;
		{&lt;br /&gt;
			buf[i].enqueue(object[i]);&lt;br /&gt;
		}&lt;br /&gt;
		oktoread.signal();&lt;br /&gt;
	}&lt;br /&gt;
	procedure entry generic* get (int n)&lt;br /&gt;
	{&lt;br /&gt;
		if (!everything_set(buf))&lt;br /&gt;
			oktoread.wait();&lt;br /&gt;
		generic g=buf[n].dequeue();&lt;br /&gt;
		if (not_full(buf)&lt;br /&gt;
			oktowrite.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-stefano92&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=459</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=459"/>
		<updated>2014-03-17T12:07:17Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2011.02.11&amp;diff=446</id>
		<title>ProvaTeorica 2011.02.11</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2011.02.11&amp;diff=446"/>
		<updated>2014-03-16T18:14:22Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*Esercizio 1: Il monitor lifocs che lo studente deve implementare, realizza una critical section LIFO. I processi per usare &lt;br /&gt;
la critical section LIFO usano il seguente protocollo:&lt;br /&gt;
n1=lifocs.enter()&lt;br /&gt;
…. codice critico&lt;br /&gt;
n2=lifocs.exit()&lt;br /&gt;
quando un processo rilascia la sezione critica e ci sono processi in attesa di entrare, deve venir assegnata la sezione &lt;br /&gt;
critica al processo che ha fatto l'ultima richiesta (in ordine di tempo).&lt;br /&gt;
Le funzioni enter e exit devono dare come valore di ritorno il numero di processi in attesa di entrare nella sezione critica.&lt;br /&gt;
I valori n1 e n2 sono correlati fra loro?*/&lt;br /&gt;
&lt;br /&gt;
monitor lifocs&lt;br /&gt;
{&lt;br /&gt;
	int inc=0;&lt;br /&gt;
	bool occupy=false;&lt;br /&gt;
	condition *pila;&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		inc++;&lt;br /&gt;
		if(occupy)&lt;br /&gt;
			pila[k-1].wait();&lt;br /&gt;
		inc--;&lt;br /&gt;
		occupy=true;&lt;br /&gt;
		return i;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		occupy=false;&lt;br /&gt;
		if(k!=0)&lt;br /&gt;
			pila[k-1].signal();&lt;br /&gt;
		return k;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-furt&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2011.02.11&amp;diff=445</id>
		<title>ProvaTeorica 2011.02.11</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2011.02.11&amp;diff=445"/>
		<updated>2014-03-16T18:13:33Z</updated>

		<summary type="html">&lt;p&gt;Stefano 92: Created page with &amp;quot;Esercizio 1  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; /*Esercizio 1: Il monitor lifocs che lo studente deve implementare, realizza una critical section LIFO. I processi per usare  la critic...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*Esercizio 1: Il monitor lifocs che lo studente deve implementare, realizza una critical section LIFO. I processi per usare &lt;br /&gt;
la critical section LIFO usano il seguente protocollo:&lt;br /&gt;
n1=lifocs.enter()&lt;br /&gt;
…. codice critico&lt;br /&gt;
n2=lifocs.exit()&lt;br /&gt;
quando un processo rilascia la sezione critica e ci sono processi in attesa di entrare, deve venir assegnata la sezione &lt;br /&gt;
critica al processo che ha fatto l'ultima richiesta (in ordine di tempo).&lt;br /&gt;
Le funzioni enter e exit devono dare come valore di ritorno il numero di processi in attesa di entrare nella sezione critica.&lt;br /&gt;
I valori n1 e n2 sono correlati fra loro?*/&lt;br /&gt;
&lt;br /&gt;
monitor lifocs&lt;br /&gt;
{&lt;br /&gt;
	int inc=0;&lt;br /&gt;
	bool occupy=false;&lt;br /&gt;
	condition *pila;&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter()&lt;br /&gt;
	{&lt;br /&gt;
		inc++;&lt;br /&gt;
		if(occupy)&lt;br /&gt;
			pila[k-1].wait();&lt;br /&gt;
		inc--;&lt;br /&gt;
		occupy=true;&lt;br /&gt;
		return i;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit()&lt;br /&gt;
	{&lt;br /&gt;
		occupy=false;&lt;br /&gt;
		if(k!=0)&lt;br /&gt;
			pila[k-1].signal();&lt;br /&gt;
		return k;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stefano 92</name></author>
	</entry>
</feed>