p39-barz - -39- IMPLEMENTING SEMAPHORES BY BINARY...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: -39- IMPLEMENTING SEMAPHORES BY BINARY SEMAPHORES Hans W. B arz I n s t i t u t f u r I n f o r m a t i k U n i v e r s i t y o f Bonn 53 Bonn 1 W est Germany K eyw ords: p a r a l I e } p r o c e s s i n g , s y n c h r o n i z a t i o n , sem aphores, b i n a r y sem aphores, s p l i t b i n a r y semaphores adequacy o f an i m p l e m e n t a t i o n INTRODUCTION Presenting the sem~phor mechanism, D ijk s tra [2 ] supposed every semaphore so lu tio n to be describable using only binary semaphores. In th is paper, several e a r l i e r solutions are analysed and.new a lte rn a tiv e s are introduced. The s o lu tio n w hich is f i n a l l y proposed may be regarded as optimal w ith respect to the number of~a~dditional semaphores a n d v a ria b le s . The common proceeding is to give a s u b s titu tio n fo r every P- or V -operation. SUBST I TUT I ON i The f i r s t attempt may often r e s u lt in a v e r s io n s im ila r to L ip to n 's [1 0 ]. s u b s titu tio n f o r ~ a P(s i ) : s u b s titu tio n T fo r a V(s i) : P (sl) ; xi:= xi-1 ; _~ xi< 0 then begin V(sl); P(s2i ) end else V (s!);; P (sl) ; X . := X.+I ; l I if xi~ D then V(s~) ; v(sli ) ; i n i t i a l values: I 2 x i = i n i t i a l value s i , s.z = I , sz = 0 SIGPLAN iNotices, Vi8 #2, February, 1983 -40-~ This attempt contains an e rro r since s~ is not a binary semaphore in general. The following example shows this. Process I Process 2 Process 3 o o o P(s I) ; P(s I) ; o v(s I) ; v(s I) ; o o o i n i t i a l value: s. = 0 l EXAMPLE 1 A fte r s u b s titu tin g , the fo llo w in g execution-sequence is possible: Process i enters f i r s t the substituted segment fo r P(s I) - i . e . tr ie s to pass P(s I) in the o rig in a l program - and has to w ait fo r P(s~) w ith x l= - I . Now Process 2 enters i t s substituted segment and has to w a it fo r P(s~) w ith x1= -2 . At la s t Process 3 executes the two substituted V(s I) -statements w ithout the other processes being active, The re s u lt of th is sequence is X l= 0 and s~= 2 o This~solution is erroneous because several V(s~)-operations are a b le to execute w ithout a P(s~)-opera~tion in between. Correcting th is leads to the next s u b s titu tio n . SUBSTITUTION 2 This version which is due to JUrgens [6 ] contains s p l i t binary semaphores [3 ,7 ]. Consequently, these semaphores have not been used f i r s t by Hoare [4] as noted in D ijkstra [3 ]. -4]- s u b s titu tio n f o r a P(si) : P (s I) ; xi:= x.-1 ; 1 _~_ x i < 0 then begin v(sl); P(s~); V(s3i ) ~__ else V(s I) ; i n i t i a l values: s u b s titu tio n fo r a V(s i ) : P Ca I) ; x. :=x.+1 ; 1 1 ifx. ~0 then else V(s I) ; I 2 3 x.= i n i t i a l value s. , s.= I e s . = O , s.= I 1 1 1 1 1...
View Full Document

This note was uploaded on 01/18/2012 for the course INFORMATIK 2011 taught by Professor Phanthuongcang during the Winter '11 term at Cornell University (Engineering School).

Page1 / 7

p39-barz - -39- IMPLEMENTING SEMAPHORES BY BINARY...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online