<?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_20-01-2015</id>
	<title>Prova Teorica 20-01-2015 - 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_20-01-2015"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_20-01-2015&amp;action=history"/>
	<updated>2026-05-17T11:23:45Z</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_20-01-2015&amp;diff=1137&amp;oldid=prev</id>
		<title>BAGG at 12:03, 1 June 2015</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_20-01-2015&amp;diff=1137&amp;oldid=prev"/>
		<updated>2015-06-01T12:03:34Z</updated>

		<summary type="html">&lt;p&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 12:03, 1 June 2015&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-l16&quot; &gt;Line 16:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 16:&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;source lang=&amp;quot;c&amp;quot;&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;source lang=&amp;quot;c&amp;quot;&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;div&gt;#define MAX 42&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;#define MAX 42&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;#define empty NULL&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;monitor lwlrbb {&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;monitor lwlrbb {&lt;/div&gt;&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-l32&quot; &gt;Line 32:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 31:&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;     entry void write(generic_type val) {&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;     entry void write(generic_type val) {&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;         if(count == MAX) {			/* se count è MAX non si può scrivere  */&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;         if(count == MAX) {			/* se count è MAX non si può scrivere  */&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;             if(nw == MAX) {			/* se la coda è piena devo fare spazio */&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;             if(nw == MAX) {			/* se la coda è piena devo fare spazio */	&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 class=&quot;diffchange diffchange-inline&quot;&gt;bb[&lt;/del&gt;rear&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;] &lt;/del&gt;= &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;empty &lt;/del&gt;;	&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;	&lt;/del&gt;/* rear indica il più vecchio elemento ancora da leggere */&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;                 rear = &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;(rear + 1)%MAX &lt;/ins&gt;; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;        &lt;/ins&gt;/* rear indica il più vecchio elemento ancora da leggere&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, lo incremento --&amp;gt; salto l'elemento &lt;/ins&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;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 class=&quot;diffchange diffchange-inline&quot;&gt;                rear = (rear + 1)%MAX ;&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;                 count -= 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;                 count -= 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;                 nw += 1 ;			/* incremento prima perchè anche se la coda è piena ora dopo la signal ci sarà un posto...  */&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;                 nw += 1 ;			/* incremento prima perchè anche se la coda è piena ora dopo la signal ci sarà un posto...  */&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>BAGG</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_20-01-2015&amp;diff=1135&amp;oldid=prev</id>
		<title>BAGG: Soluzione di Cristiano Piemontese all'esercizio c.1</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_Teorica_20-01-2015&amp;diff=1135&amp;oldid=prev"/>
		<updated>2015-05-31T10:29:08Z</updated>

		<summary type="html">&lt;p&gt;Soluzione di Cristiano Piemontese all&amp;#039;esercizio c.1&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Es. c.1==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Scrivere il monitor lwlrbb. Il monitor deve implementare le seguenti procedure entry:&lt;br /&gt;
     - void write(generic_type val);&lt;br /&gt;
     - generic_type read(void);&lt;br /&gt;
&lt;br /&gt;
Il lwlrbb si comporta come un bounded buffer di MAX elementi che coordina l'attivita' di numerosi processi produttori/scrittori &lt;br /&gt;
e numerosi lettori/consumatori. lwlrbb ammette un numero massimo (sempre MAX) di lettori e scrittori in attesa.&lt;br /&gt;
&lt;br /&gt;
Se il buffer e' vuoto e ci sono piu' gia' MAX lettori in attesa, il lettore che e' in attesa da piu' tempo esce resituendo NULL.&lt;br /&gt;
&lt;br /&gt;
In ugual modo se il buffer e' completamente pieno e ci sono gia' MAX scrittori che attendono di scrivere viene perduto il valore che da&lt;br /&gt;
piu' tempo nel buffer attende di venir letto, il primo processo in attesa di scrivere puo' cosi' scrivere il suo elemento nel buffer e sbloccarsi.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Soluzione di BAGG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define MAX 42&lt;br /&gt;
#define empty NULL&lt;br /&gt;
&lt;br /&gt;
monitor lwlrbb {&lt;br /&gt;
    generic_type bb[] ;&lt;br /&gt;
    int count, front, rear ; 	/* rispettivamente: numero elementi, dove scrivere nel buffer, dove leggere nel buffer */&lt;br /&gt;
    int nw, nr ; 		/* rispettivamente numero di writer e reader */&lt;br /&gt;
    bool exit ; 		/* server ai reader per sapere se devono ritornare NULL al loro rientro nel monitor  */&lt;br /&gt;
    condition canr, canw ;&lt;br /&gt;
&lt;br /&gt;
    lwlrbb(void) {&lt;br /&gt;
        bb = new generic_type[MAX] ;&lt;br /&gt;
        count = front = rear = nw = nr = exit = 0 ;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    entry void write(generic_type val) {&lt;br /&gt;
        if(count == MAX) {			/* se count è MAX non si può scrivere  */&lt;br /&gt;
            if(nw == MAX) {			/* se la coda è piena devo fare spazio */&lt;br /&gt;
                bb[rear] = empty ;		/* rear indica il più vecchio elemento ancora da leggere */&lt;br /&gt;
                rear = (rear + 1)%MAX ;&lt;br /&gt;
                count -= 1 ;&lt;br /&gt;
                nw += 1 ;			/* incremento prima perchè anche se la coda è piena ora dopo la signal ci sarà un posto...  */&lt;br /&gt;
                canw.signal() ;			/* ora il primo che aspettava può scrivere --&amp;gt; lo sveglio  */&lt;br /&gt;
                canw.wait() ;&lt;br /&gt;
                nw -= 1 ;&lt;br /&gt;
            } else {				/* se la coda non è piena devo comunque aspettare...  */&lt;br /&gt;
                nw += 1 ;&lt;br /&gt;
                canw.wait() ;&lt;br /&gt;
                nw -=1 ;&lt;br /&gt;
            }&lt;br /&gt;
        } &lt;br /&gt;
	bb[front] = val ;					&lt;br /&gt;
        front = (front + 1)%MAX ;&lt;br /&gt;
        count += 1 ;&lt;br /&gt;
        canr.signal() ;				/* potrebbe esserci un reader che aspetta --&amp;gt; segnalo che ho scritto e si può leggere  */&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    entry generic_type read(void) {&lt;br /&gt;
        if(count == 0) {			/* se non c'è nulla da leggere allora devo aspettare  */&lt;br /&gt;
            if(nr == MAX) {			/* se la coda è piena setto exit, che i reader controllano per sapere se sono stati svegliati per ritornare NULL  */&lt;br /&gt;
                exit = 1 ;&lt;br /&gt;
                canr.signal() ;		        /* sveglio il condannato...  */&lt;br /&gt;
            } nr += 1 ;				/* mi accodo... */&lt;br /&gt;
            canr.wait() ;&lt;br /&gt;
            nr -= 1 ;&lt;br /&gt;
            if(exit) {				/* se sono il condannato resetto la variabile ed esco...  */&lt;br /&gt;
                 exit = 0 ;&lt;br /&gt;
                 return NULL ;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        generic_type r = bb[rear] ;&lt;br /&gt;
        rear = (rear + 1)%MAX ;&lt;br /&gt;
        count -= 1 ;&lt;br /&gt;
        canw.signal() ;				/* ho letto, quindi si è liberato un posto e almeno un writer può scrivere... */&lt;br /&gt;
        return r ;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>BAGG</name></author>
	</entry>
</feed>