<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=Prova_Teorica_2008.01.16</id>
	<title>Prova Teorica 2008.01.16 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=Prova_Teorica_2008.01.16"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;action=history"/>
	<updated>2026-04-16T18:39:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;diff=550&amp;oldid=prev</id>
		<title>TomOgn: /* Esercizio 1 */</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;diff=550&amp;oldid=prev"/>
		<updated>2014-04-06T18:12:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Esercizio 1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:12, 6 April 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l84&quot; &gt;Line 84:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 84:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Si avrebbe deadlock, in quanto si potrebbe generare la situazione di avere il guardaroba pieno e il primo della coda che intende consegnare una giacca.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[B] &lt;/ins&gt;Si avrebbe deadlock, in quanto si potrebbe generare la situazione di avere il guardaroba pieno e il primo della coda che intende consegnare una giacca.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** Salva l'adozione di una politica (iniqua) nel caso del guardaroba pieno. Segnatamente quella di rimandare alla fine della coda tutti i processi che consegnano la giacca.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** Salva l'adozione di una politica (iniqua) nel caso del guardaroba pieno. Segnatamente quella di rimandare alla fine della coda tutti i processi che consegnano la giacca.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Esercizio 3 ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Esercizio 3 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>TomOgn</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;diff=549&amp;oldid=prev</id>
		<title>TomOgn: /* Esercizio 3 */</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;diff=549&amp;oldid=prev"/>
		<updated>2014-04-06T18:11:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Esercizio 3&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:11, 6 April 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l132&quot; &gt;Line 132:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 132:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          vp = 1;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          vp = 1;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;         if (lock = 1&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          lock += 1;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          lock += 1;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          F(lock, vp);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          F(lock, vp);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>TomOgn</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;diff=548&amp;oldid=prev</id>
		<title>TomOgn: Created page with &quot;&lt;h1&gt;http://www.cs.unibo.it/~renzo/so/compiti/2008-01-16.tot.pdf&lt;/h1&gt;  == Esercizio 1 ==  &lt;syntaxhighlight lang=&quot;C&quot;&gt; monitor guardaroba_russo { 	Ritira = 0; Consegna = 1; Prend...&quot;</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2008.01.16&amp;diff=548&amp;oldid=prev"/>
		<updated>2014-04-06T18:10:17Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2008-01-16.tot.pdf&amp;lt;/h1&amp;gt;  == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; monitor guardaroba_russo { 	Ritira = 0; Consegna = 1; Prend...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2008-01-16.tot.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;
monitor guardaroba_russo&lt;br /&gt;
{&lt;br /&gt;
	Ritira = 0; Consegna = 1; Prendi = 2;&lt;br /&gt;
	queue waiting[2] = {0, 0};&lt;br /&gt;
	queue all;&lt;br /&gt;
	condition ok[3];&lt;br /&gt;
	count = 0;&lt;br /&gt;
	waitingAny = False; waitingMax = False;&lt;br /&gt;
	output;&lt;br /&gt;
	&lt;br /&gt;
	// Cancella la prima occorrenza di &amp;lt;Ritira&amp;gt; nella coda &amp;lt;all&amp;gt;&lt;br /&gt;
	deleteRitira();&lt;br /&gt;
	&lt;br /&gt;
	item prendi()&lt;br /&gt;
	{&lt;br /&gt;
		if (count == MAX)&lt;br /&gt;
		{&lt;br /&gt;
			if (waiting[Ritira].Count == 0)&lt;br /&gt;
			{&lt;br /&gt;
				waitingMax = True;&lt;br /&gt;
				ok[Prendi].wait();&lt;br /&gt;
			}&lt;br /&gt;
			return waiting[Ritira].dequeue();&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			if (all.Count == 0)&lt;br /&gt;
			{&lt;br /&gt;
				waitingAny = True;&lt;br /&gt;
				ok[Prendi].wait();&lt;br /&gt;
                                waitingAny = False;&lt;br /&gt;
			}&lt;br /&gt;
			return waiting[all.read()].dequeue();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	dai(item x)&lt;br /&gt;
	{&lt;br /&gt;
		if (waitingMax)&lt;br /&gt;
		{&lt;br /&gt;
			waitingMax = False;&lt;br /&gt;
			deleteRitira();&lt;br /&gt;
			output = x;&lt;br /&gt;
			// Se il dipendente e' stato riattivato tramite signal, la seguente va a vuoto&lt;br /&gt;
			ok[Ritira].signal();&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			output = x;&lt;br /&gt;
			// Se il dipendente e' stato riattivato tramite signal, la seguente va a vuoto&lt;br /&gt;
			ok[all.dequeue()].signal();		&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	contrassegno consegna(giacca g)&lt;br /&gt;
	{&lt;br /&gt;
		all.enqueue(Consegna);&lt;br /&gt;
		waiting[Consegna].enqueue(g);&lt;br /&gt;
		if (waitingAny)&lt;br /&gt;
			ok[Prendi].signal();&lt;br /&gt;
		else&lt;br /&gt;
			ok[Consegna].wait();&lt;br /&gt;
		count++;&lt;br /&gt;
		return output;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	giacca ritira(contrassegno c)&lt;br /&gt;
	{&lt;br /&gt;
		all.enqueue(Ritira);&lt;br /&gt;
		waiting[Ritira].enqueue(c);&lt;br /&gt;
		if (waitingAny || waitingMax)&lt;br /&gt;
			ok[Prendi].signal();&lt;br /&gt;
		else&lt;br /&gt;
			ok[Ritira].wait();&lt;br /&gt;
		count--;&lt;br /&gt;
		return output;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Si avrebbe deadlock, in quanto si potrebbe generare la situazione di avere il guardaroba pieno e il primo della coda che intende consegnare una giacca.&lt;br /&gt;
** Salva l'adozione di una politica (iniqua) nel caso del guardaroba pieno. Segnatamente quella di rimandare alla fine della coda tutti i processi che consegnano la giacca.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Esercizio 3 ==&lt;br /&gt;
&lt;br /&gt;
* Ad input immutato, F(x, y) non puo' sostituire la Test&amp;amp;Set:&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! x || y || Test&amp;amp;Set: x y || F(x,y): x1 x y&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || '''1 0'''     || 0 0 undefined&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || '''1 0'''     || 0 1 undefined&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || '''1 1'''     || 1 0 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || '''1 1'''     || 1 1 0&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* Mediante le seguenti modifiche diventa possibile:&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! x = x + 1 || y = 1 || F(x,y): x1 x y&lt;br /&gt;
|-&lt;br /&gt;
| 1         || 1     || 1  '''1''' '''0'''&lt;br /&gt;
|-&lt;br /&gt;
| 1         || 1     || 1  '''1''' '''0'''&lt;br /&gt;
|-&lt;br /&gt;
| 2         || 1     || 2  '''1''' '''1'''&lt;br /&gt;
|-&lt;br /&gt;
| 2         || 1     || 2  '''1''' '''1'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* In termini di pseudocodice:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
shared lock = 0;&lt;br /&gt;
&lt;br /&gt;
process P&lt;br /&gt;
{&lt;br /&gt;
   int vp;&lt;br /&gt;
   while (True)&lt;br /&gt;
   {&lt;br /&gt;
      do&lt;br /&gt;
      {&lt;br /&gt;
         vp = 1;&lt;br /&gt;
         if (lock = 1&lt;br /&gt;
         lock += 1;&lt;br /&gt;
         F(lock, vp);&lt;br /&gt;
      } while(vp);&lt;br /&gt;
      // &amp;lt;critical section&amp;gt;&lt;br /&gt;
      lock = 0;&lt;br /&gt;
      // &amp;lt;/critical section&amp;gt;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>TomOgn</name></author>
	</entry>
</feed>