<?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_2007.09.07</id>
	<title>Prova Teorica 2007.09.07 - 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_2007.09.07"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2007.09.07&amp;action=history"/>
	<updated>2026-05-06T00:06:00Z</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_2007.09.07&amp;diff=587&amp;oldid=prev</id>
		<title>TomOgn: Created page with &quot;=[http://www.cs.unibo.it/~renzo/so/compiti/2007-09-07.tot.pdf TESTO COMPITO]= =CONCORRENZA= ==Esercizio 1== &lt;syntaxhighlight lang=&quot;Java&quot;&gt; Monitor fabbrica { 	Queue ruote, scoc...&quot;</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_2007.09.07&amp;diff=587&amp;oldid=prev"/>
		<updated>2014-04-23T10:28:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=[http://www.cs.unibo.it/~renzo/so/compiti/2007-09-07.tot.pdf TESTO COMPITO]= =CONCORRENZA= ==Esercizio 1== &amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt; Monitor fabbrica { 	Queue ruote, scoc...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=[http://www.cs.unibo.it/~renzo/so/compiti/2007-09-07.tot.pdf TESTO COMPITO]=&lt;br /&gt;
=CONCORRENZA=&lt;br /&gt;
==Esercizio 1==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
Monitor fabbrica&lt;br /&gt;
{&lt;br /&gt;
	Queue ruote, scocche;&lt;br /&gt;
	Condition produttoreRuota, produttoreScocca, assemblatore;&lt;br /&gt;
&lt;br /&gt;
	void deposita_ruota(Ruota r)&lt;br /&gt;
	{&lt;br /&gt;
		if (ruote.Count == 64)&lt;br /&gt;
			produttoreRuota.wait();&lt;br /&gt;
&lt;br /&gt;
		ruote.enqueue(r);&lt;br /&gt;
&lt;br /&gt;
		if (ruote.Count &amp;gt;= 4 &amp;amp;&amp;amp; scocche.Count &amp;gt;= 1)&lt;br /&gt;
			assemblatore.signal();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	void deposita_scocca(Scocca s)&lt;br /&gt;
	{&lt;br /&gt;
		if (scocche.Count == 8)&lt;br /&gt;
			produttoreScocca.wait();&lt;br /&gt;
&lt;br /&gt;
		scocche.enqueue(s);&lt;br /&gt;
&lt;br /&gt;
		if (ruote.Count &amp;gt;= 4)&lt;br /&gt;
			assemblatore.signal();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	void preleva_pezzi(Ruota r[4], Scocca *s)&lt;br /&gt;
	{&lt;br /&gt;
		if (ruote.Count &amp;lt; 4 || scocche.Count &amp;lt; 1)&lt;br /&gt;
			assemblatore.wait();&lt;br /&gt;
&lt;br /&gt;
		for (int i = 0; i &amp;lt; 4; i++)&lt;br /&gt;
			r[i] = ruote.dequeue();&lt;br /&gt;
		*s = scocche.dequeue();&lt;br /&gt;
&lt;br /&gt;
		for (int i = 0; i &amp;lt; 4; i++)&lt;br /&gt;
			produttoreRuota.signal();&lt;br /&gt;
		produttoreScocca.signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==Esercizio 2==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
// (1) Yes, it is possible.&lt;br /&gt;
&lt;br /&gt;
void nbSend(Message msg, Pid dst)&lt;br /&gt;
{&lt;br /&gt;
	asend(&amp;lt;msg, getpid()&amp;gt;, dst);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Message nbReceive(Pid src)&lt;br /&gt;
{&lt;br /&gt;
	Message fake = Message();&lt;br /&gt;
	asend(fake, getpid());&lt;br /&gt;
	&amp;lt;msg, pid&amp;gt; = areceive(*);&lt;br /&gt;
	&lt;br /&gt;
	return (pid == src)? msg : NULL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// (2) Yes, it is possible, but it requires busy waiting.&lt;br /&gt;
&lt;br /&gt;
void aSend(Message msg, Pid dst)&lt;br /&gt;
{&lt;br /&gt;
	nbsend(msg, dst);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Message aReceive(Pid sender)&lt;br /&gt;
{&lt;br /&gt;
	Message msg;&lt;br /&gt;
&lt;br /&gt;
	// Blocking effect through busy waiting&lt;br /&gt;
	while (!(msg = nbreceive(sender)));&lt;br /&gt;
&lt;br /&gt;
	return msg;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>TomOgn</name></author>
	</entry>
</feed>