Difference between revisions of "Prova teorica 2013.05.30"
Jump to navigation
Jump to search
(Created page with "[http://www.cs.unibo.it/~renzo/so/compiti/2013.05.30.tot.pdf Link al testo] == Esercizio 2 == ===Soluzione di FedericoB=== Creo i v2p con i semafori normali <source lang="text...") |
(No difference)
|
Latest revision as of 16:16, 9 May 2017
Esercizio 2
Soluzione di FedericoB
Creo i v2p con i semafori normali
class v2p
semaphore s;
v2p(val)
new s(val);
p()
mutex.p()
s.p()
s.p()
mutex.v()
v()
s.v
Creiamo i semafori normali con i v2p
class semaphore
v2p s;
v2p mutex=1;
int val;
semaphore(initval):
val = initval
p()
mutex.p()
val--
if (val<0)
mutex.v()
mutex.v()
s.p()
mutex.v()
mutex.v()
v():
mutex.p()
val++
if (val<=0)
s.v()
s.v()