<?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=Silas</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=Silas"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php/Special:Contributions/Silas"/>
	<updated>2026-05-05T02:49:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_teorica_2015.02.14&amp;diff=1900</id>
		<title>Prova teorica 2015.02.14</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_teorica_2015.02.14&amp;diff=1900"/>
		<updated>2017-05-26T15:42:17Z</updated>

		<summary type="html">&lt;p&gt;Silas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2015.02.14.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
== Esercizio c.1 ==&lt;br /&gt;
===Soluzione di Silas===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define MAX &lt;br /&gt;
&lt;br /&gt;
monitor altcolbb{&lt;br /&gt;
	queue buff;&lt;br /&gt;
	color_t last_color; //0: red, 1:blue, -1:&amp;quot;superstate&amp;quot;, means that both red and blue are accepted&lt;br /&gt;
	int wait_red, wait_blue;&lt;br /&gt;
	condition ok2read, redok, blueok;&lt;br /&gt;
&lt;br /&gt;
	void altcolbb(void){&lt;br /&gt;
		buff = new queue();&lt;br /&gt;
		last_color = -1;&lt;br /&gt;
		wait_red = wait_blue = 0;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(color_t color, generic_type val){&lt;br /&gt;
		if(last_color == color || buff.length() == MAX){ //we can't enqueue if the colors are the same or if the buffer is full&lt;br /&gt;
			if(color == 0){ //enqueue to &amp;quot;reds&amp;quot;&lt;br /&gt;
				wait_red++;&lt;br /&gt;
				redok.wait();&lt;br /&gt;
				wait_red--;&lt;br /&gt;
			}else{ //enqueue to &amp;quot;blues&amp;quot;&lt;br /&gt;
				wait_blue++;&lt;br /&gt;
				blueok.wait();&lt;br /&gt;
				wait_blue--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		buff.enqueue(val); //append val and update last_color&lt;br /&gt;
		last_color = color;&lt;br /&gt;
		ok2read.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry generic_type read(void){&lt;br /&gt;
		if(buff.length() == 0)&lt;br /&gt;
			ok2read.wait();&lt;br /&gt;
		generic_type ret = buff.dequeue();&lt;br /&gt;
		if(buff.length() == 0)&lt;br /&gt;
			last_color = -1; //if buff is empty both colors can now be added&lt;br /&gt;
		switch(last_color){&lt;br /&gt;
			case -1: {&lt;br /&gt;
					if(wait_red&amp;gt;wait_blue) //if there are more &amp;quot;reds&amp;quot; waiting to write we signal them&lt;br /&gt;
						redok.signal();&lt;br /&gt;
					else&lt;br /&gt;
						blueok.signal(); //otherwise we signal &amp;quot;blues&amp;quot;&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
			case 0: {&lt;br /&gt;
					blueok.signal();&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
			case 1: {&lt;br /&gt;
					redok.signal();&lt;br /&gt;
					break;&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;
== Esercizio c.2 ==&lt;br /&gt;
===Soluzione di Silas===&lt;br /&gt;
I semafori garantiscono che A e B vengano eseguiti in maniera sequenziale e che accedano in maniera mutualmente esclusiva ad n, quindi l'unica variazione possibile è il thread di inizio per la sequenza.&lt;br /&gt;
Nel caso sia A ad accedere per primo alla CS si ha: n = ((1*2)+2)*3 = 12&lt;br /&gt;
Nel caso sia invece B ad accedere per primo alla C si ha: n = (((0*2)+1)*3)+2 = 5&lt;br /&gt;
Quindi n = 12 e n = 5 sono i due possibili valori.&lt;/div&gt;</summary>
		<author><name>Silas</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_teorica_2015.02.14&amp;diff=1899</id>
		<title>Prova teorica 2015.02.14</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_teorica_2015.02.14&amp;diff=1899"/>
		<updated>2017-05-26T15:16:50Z</updated>

		<summary type="html">&lt;p&gt;Silas: /* Soluzione di Silas */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2015.02.14.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
== Esercizio c.1 ==&lt;br /&gt;
===Soluzione di Silas===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define MAX &lt;br /&gt;
&lt;br /&gt;
monitor altcolbb{&lt;br /&gt;
	queue buff;&lt;br /&gt;
	color_t last_color; //0: red, 1:blue, -1:&amp;quot;superstate&amp;quot;, means that both red and blue are accepted&lt;br /&gt;
	int wait_red, wait_blue;&lt;br /&gt;
	condition ok2read, redok, blueok;&lt;br /&gt;
&lt;br /&gt;
	void altcolbb(void){&lt;br /&gt;
		buff = new queue();&lt;br /&gt;
		last_color = -1;&lt;br /&gt;
		wait_red = wait_blue = 0;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(color_t color, generic_type val){&lt;br /&gt;
		if(last_color == color || buff.length() == MAX){ //we can't enqueue if the colors are the same or if the buffer is full&lt;br /&gt;
			if(color == 0){ //enqueue to &amp;quot;reds&amp;quot;&lt;br /&gt;
				wait_red++;&lt;br /&gt;
				redok.wait();&lt;br /&gt;
				wait_red--;&lt;br /&gt;
			}else{ //enqueue to &amp;quot;blues&amp;quot;&lt;br /&gt;
				wait_blue++;&lt;br /&gt;
				blueok.wait();&lt;br /&gt;
				wait_blue--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		buff.enqueue(val); //append val and update last_color&lt;br /&gt;
		last_color = color;&lt;br /&gt;
		ok2read.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry generic_type read(void){&lt;br /&gt;
		if(buff.length() == 0)&lt;br /&gt;
			ok2read.wait();&lt;br /&gt;
		generic_type ret = buff.dequeue();&lt;br /&gt;
		if(buff.length() == 0)&lt;br /&gt;
			last_color = -1; //if buff is empty both colors can now be added&lt;br /&gt;
		switch(last_color){&lt;br /&gt;
			case -1: {&lt;br /&gt;
					if(wait_red&amp;gt;wait_blue) //if there are more &amp;quot;reds&amp;quot; waiting to write we signal them&lt;br /&gt;
						redok.signal();&lt;br /&gt;
					else&lt;br /&gt;
						blueok.signal(); //otherwise we signal &amp;quot;blues&amp;quot;&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
			case 0: {&lt;br /&gt;
					blueok.signal();&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
			case 1: {&lt;br /&gt;
					redok.signal();&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Silas</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_teorica_2015.02.14&amp;diff=1898</id>
		<title>Prova teorica 2015.02.14</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_teorica_2015.02.14&amp;diff=1898"/>
		<updated>2017-05-26T15:14:05Z</updated>

		<summary type="html">&lt;p&gt;Silas: Created page with &amp;quot;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2015.02.14.tot.pdf]  == Esercizio c.1 == ===Soluzione di Silas=== &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; #define MAX   monitor altcolbb{ 	...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2015.02.14.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
== Esercizio c.1 ==&lt;br /&gt;
===Soluzione di Silas===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define MAX &lt;br /&gt;
&lt;br /&gt;
monitor altcolbb{&lt;br /&gt;
	queue buff;&lt;br /&gt;
	color_t last_color; //0: red, 1:blue, -1:&amp;quot;superstate&amp;quot;, means that both red and blue are accepted&lt;br /&gt;
	int wait_red, wait_blue;&lt;br /&gt;
	condition ok2read, redok, blueok;&lt;br /&gt;
&lt;br /&gt;
	void altcolbb(void){&lt;br /&gt;
		buff = new queue();&lt;br /&gt;
		last_color = -1;&lt;br /&gt;
		wait_red = wait_blue = 0;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry void write(color_t color, generic_type val){&lt;br /&gt;
		if(last_color == color || buff.length() == MAX){ //we can't enqueue if the colors are the same or if the buffer is full&lt;br /&gt;
			if(color == 0){ //enqueue to &amp;quot;reds&amp;quot;&lt;br /&gt;
				wait_red++;&lt;br /&gt;
				redok.wait();&lt;br /&gt;
				wait_red--;&lt;br /&gt;
			}else{&lt;br /&gt;
				wait_blue++;&lt;br /&gt;
				blueok.wait();&lt;br /&gt;
				wait_blue--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		buff.enqueue(val);&lt;br /&gt;
		last_color = color;&lt;br /&gt;
		ok2read.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry generic_type read(void){&lt;br /&gt;
		if(buff.length() == 0)&lt;br /&gt;
			ok2read.wait();&lt;br /&gt;
		generic_type ret = buff.dequeue();&lt;br /&gt;
		if(buff.length() == 0)&lt;br /&gt;
			last_color = -1;&lt;br /&gt;
		switch(last_color){&lt;br /&gt;
			case -1: {&lt;br /&gt;
					if(wait_red&amp;gt;wait_blue)&lt;br /&gt;
						redok.signal();&lt;br /&gt;
					else&lt;br /&gt;
						blueok.signal();&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
			case 0: {&lt;br /&gt;
					redok.signal();&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
			case 1: {&lt;br /&gt;
					blueok.signal();&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Silas</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_teoriche&amp;diff=1897</id>
		<title>Prove teoriche</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_teoriche&amp;diff=1897"/>
		<updated>2017-05-26T14:59:53Z</updated>

		<summary type="html">&lt;p&gt;Silas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Qui troverete alcune prove teoriche svolte, in modo da poter discutere sull'elaborato''&lt;br /&gt;
&lt;br /&gt;
''Le prove sono svolte da studenti e servono come base per la discussione. Le soluzioni possono essere errate''&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2015.02.14]]&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2015.01.20]]&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2014.09.24]]&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2014.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2014.06.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2014.06.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.02.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova teorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[Prova_Teorica 2013.02.14]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2011.05.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&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;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2005.11.04]]&lt;/div&gt;</summary>
		<author><name>Silas</name></author>
	</entry>
</feed>