[so] so Digest, Vol 65, Issue 5
Razvan Pistolea
razvy000 at yahoo.com
Sat Sep 17 14:20:37 EEST 2011
SemaforGeneral(N){
c = N // contor; lasa maxim N
mutex = SemaforBinar(1) // protejeaza contorul
s2 = SemaforBinar(N>1?1:0) // implementeaza "notificarea"
wait()
s2.wait()
mutex.wait()
c--
if c > 0
s2.release()
mutex.release()
release()
mutex.wait()
c++
if c == 1
s2.release()
mutex.release()
}
//exemplu:
s = SemaforGeneral(2) // c = 2, mutex = 1, s2 = 1
proces1: s.wait() // c = 1, mutex = 1, s2 = 0
p2: s.wait() // c = 0, mutex = 1, s2 = 0
p3: s.wait() // c = 0, mutex = 1, s2 = 0 p3 blocat in s2
p4: s.wait() // c = 0, mutex = 1, s2 = 0 p4 blocat in s2
p2: s.release() // c = 1 deblocheaza p4 (p3 sau p4)
// p4 se blocheaza (posibil in mutex) dar e deblocat tot de p2
// c = 0, mutex = 1, s2 = 0
p4: s.release() // c = 1, deblocheaza p3, c = 0, mutex = 1, s2 = 0
p1: s.release()
p3: s.release()
// mia placut mult "little book of semaphores"
atasez si document daca formatarea este urata
--- On Sat, 9/17/11, so-request at cursuri.cs.pub.ro <so-request at cursuri.cs.pub.ro> wrote:
From: so-request at cursuri.cs.pub.ro <so-request at cursuri.cs.pub.ro>
Subject: so Digest, Vol 65, Issue 5
To: so at cursuri.cs.pub.ro
Date: Saturday, September 17, 2011, 2:00 AM
Send so mailing list submissions to
so at cursuri.cs.pub.ro
To subscribe or unsubscribe via the World Wide Web, visit
http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
or, via email, send a message with subject or body 'help' to
so-request at cursuri.cs.pub.ro
You can reach the person managing the list at
so-owner at cursuri.cs.pub.ro
When replying, please edit your Subject line so it is more specific
than "Re: Contents of so digest..."
Today's Topics:
1. Re: so Digest, Vol 65, Issue 4 (Razvan Pistolea)
2. Re: so Digest, Vol 65, Issue 4 (Razvan Deaconescu)
----------------------------------------------------------------------
Message: 1
Date: Fri, 16 Sep 2011 06:31:18 -0700 (PDT)
From: Razvan Pistolea <razvy000 at yahoo.com>
Subject: Re: [so] so Digest, Vol 65, Issue 4
To: so at cursuri.cs.pub.ro
Message-ID:
<1316179878.14177.YahooMailClassic at web38004.mail.mud.yahoo.com>
Content-Type: text/plain; charset="utf-8"
legat de:
"Se poate implementa un semafor folosind?doar?mutex-uri? Dar un mutex folosind?doar?semafoare?R?spuns:Un mutex se poate implementa ca un semafor binar. R?spuns afirmativ la a doua ?ntrebare.Nu?se poate implementa un semafor folosind?doar?mutex-uri ?ntruc?t avem nevoie de un mecanism de notificare atomic? ?mpreun? cu celelalte ac?iuni. Presupun?nd c? se folose?te un contor, implementarea func?iei?down?va fi:"
Am o mica nedumerire:facem o distinctie intre mutex si semafor binar? (adica ownership, numai threadul care a facut lock pe mutex poate sa faca unlock)
daca DAatunci in primul raspuns ar trebui completat semaforul cu informatie despre cine a luat (ca doar threadID care a luat semaforul sa faca unlock)
daca NUatunci un semanfor general poate fi implementat cu semafoare binare (2 sunt de ajuns) si un contor.
--- On Fri, 9/16/11, so-request at cursuri.cs.pub.ro <so-request at cursuri.cs.pub.ro> wrote:
From: so-request at cursuri.cs.pub.ro <so-request at cursuri.cs.pub.ro>
Subject: so Digest, Vol 65, Issue 4
To: so at cursuri.cs.pub.ro
Date: Friday, September 16, 2011, 2:00 AM
Send so mailing list submissions to
??? so at cursuri.cs.pub.ro
To subscribe or unsubscribe via the World Wide Web, visit
??? http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
or, via email, send a message with subject or body 'help' to
??? so-request at cursuri.cs.pub.ro
You can reach the person managing the list at
??? so-owner at cursuri.cs.pub.ro
When replying, please edit your Subject line so it is more specific
than "Re: Contents of so digest..."
Today's Topics:
???1. Subiecte examen restanta/marire - septembrie 2011
? ? ? (Razvan Deaconescu)
----------------------------------------------------------------------
Message: 1
Date: Fri, 16 Sep 2011 10:30:16 +0300
From: Razvan Deaconescu <razvan.deaconescu at cs.pub.ro>
Subject: [so] Subiecte examen restanta/marire - septembrie 2011
To: Student-SO Mailing List <so at cursuri.cs.pub.ro>
Message-ID: <1316158216.2690.70.camel at einherjar.cs.pub.ro>
Content-Type: text/plain; charset="UTF-8"
Salutare!
G?si?i pe wiki[1] subiectele de la examenele de restan??/m?rire din
sesiunea septembrie 2011.
[1] http://elf.cs.pub.ro/so/wiki/examen#examen-restanta
R?zvan
------------------------------
_______________________________________________
so mailing list
so at cursuri.cs.pub.ro
http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
End of so Digest, Vol 65, Issue 4
*********************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20110916/0ab3acac/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 16 Sep 2011 16:39:12 +0300
From: Razvan Deaconescu <razvan.deaconescu at cs.pub.ro>
Subject: Re: [so] so Digest, Vol 65, Issue 4
To: Sisteme de Operare <so at cursuri.cs.pub.ro>
Message-ID: <1316180352.2690.124.camel at einherjar.cs.pub.ro>
Content-Type: text/plain; charset="UTF-8"
On Fri, 2011-09-16 at 06:31 -0700, Razvan Pistolea wrote:
> daca NU, atunci un semanfor general poate fi implementat cu semafoare
> binare (2 sunt de ajuns) si un contor.
Cum anume?
R?zvan
------------------------------
_______________________________________________
so mailing list
so at cursuri.cs.pub.ro
http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
End of so Digest, Vol 65, Issue 5
*********************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20110917/1b203147/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: semafor.txt
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20110917/1b203147/attachment.txt>
More information about the so
mailing list