Skip to content

Commit

Permalink
add soluzione
Browse files Browse the repository at this point in the history
Aggiunge soluzione dell'esame scritto del 2024-09-10, di cui il testo è mancante al momento in cui lo carico.
Tutte le soluzioni sono prese da una foto del proiettore durante la correzione del prof avvenuta il giorno stesso dell'esame.
  • Loading branch information
Bosslibra authored Jan 5, 2025
1 parent bcb44a6 commit 65e6471
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions prove/scritto/scritto-2024-09-10-soluzione.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Soluzioni Esame 10-09-2024

Al momento in cui trascrivo le soluzioni date dal prof, manca ancora il testo dell'esame nella lista del prof.
(Queste soluzioni sono prese da una foto alla correzione fatta dal prof immediatamente dopo l'esame)


#ES C1

p.e. void addfirst(int val):
if wl>0 and wb>0:
valf = val
oklast.pop().signal()
okboth.signal()
else:
wf++
okfirst.wait()
wf--
valf = val

p.e. void addlast(int val):
if wf>0 and wb>0:
vall = val
okfirst.signal()
okboth.signal()
else:
wl++
c = new condition()
oklast.push(c)
c.wait()
wl--
vall = val

p.e. int getboth(void):
if wf>0 and wl>0:
okfirst.signal()
oklast.pop().signal()
else:
wb++
okboth.wait()
wb--
return valf+vall

#ES C2

void altsend(msg_t msg, pid_t dest):
asend(<getpid(), msg>, dest)

db
int rcount = 0
msg_t altrecv(pid_t sender):
rcount++
asend(<getpid(), TAG>, getpid())
while True:
<s,m> = arecv(ANY)
if s==getpid() and m==TAG:
break
db.add(s,m)
if rcount % 2:
while (m = db.getfirst(sender)) != None:
<s,m> = arecv(ANY)
db.add(s,m)
else:
while (m = db.getlast(sender)) != None:
<s,m> = arev(ANY)
db.add(s,m)
return m

#ES G1

10 10
P1 0,8,8 0,5,5
P2 0,5,5 0,8,8
P3 0,5,5 0,5,5
p1 richiede 4,5
6 5
P1 4,8,4 5,5,0
P2 0,5,5 0,8,8
P3 0,5,5 0,5,5
p3 richiede 3,4
3 1
P1 4,8,4 5,5,0
P2 0,5,5 0,8,8
P3 3,5,2 4,5,1
p3 termina
6 5
P1 4,8,4 5,5,0
P2 0,5,5 0,8,8
p2 chiede 3,4 ===> sospesa
## 3 1
##P1 4,8,4 5,5,0
##P2 3,5,2 4,8,4
p1 restituisce 0,3
6 8
P1 4,8,4 2,5,3
P2 0,5,5 0,8,8
p2 chiede 3,4
3 4
P1 4,8,4 2,5,3
P2 3,5,2 4,8,4

0 comments on commit 65e6471

Please sign in to comment.