p42-hemmendinger - A correct implementation of general...

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

View Full Document Right Arrow Icon
A correct implementation of general semaphores David Hemmendinger Department of Computer Science and Engineering Wright State University Dayton, Ohio 45435 csnet: dhemm@CS.wright.edu Introduction In a recent issue of Operating System Review, Kotulski points out a flaw in common text- book algorithms for the implementation of general semaphores from binary ones [2]. A small change in the code he gives for these algorithms will solve the problem. The problem If several processes interleave their execution of P and V in the following algorithms that are intended to implement general semaphore operations, it is possible to do two or more suc- cessive V operations on a binary semaphore, and the effect of these successive V's is not defined for such a semaphore. In what follow, PB and VB are binary semaphore operations; minor corrections have been made to Kotulski's code. type semaphore = record mutex, delay : binary_semaphore; count : integer end; procedure P( var s : semaphore ); begin PB(s.mutex); s.count := s.count- 1; if s.count < 0 then begin VB(s.mutex); { the critical interleaving can occur here } PB(s.delay) else VB(s.mutex) procedure V( var s : semaphore ); begin s.count := s.count + 1; if s.count ___ 0 then VB(s.delay); 42
Background image of page 1

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

View Full DocumentRight Arrow Icon
Suppose two processes each call P(s) when s.count is initially 0, and after the first has just done VB(s~nutex) but not done PB(s.delay), the second call to P proceeds to the same point. Since = -2 and s.mutex is unlocked, if two other processes then successively
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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 / 3

p42-hemmendinger - A correct implementation of general...

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

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