{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

p42-hemmendinger

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

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

A correct implementation of general semaphores David Hemmendinger Department of Computer Science and Engineering Wright State University Dayton, Ohio 45435 csnet: [email protected] 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) end; else end; VB(s.mutex) procedure V( var s : semaphore ); begin PB(s.mutex); s.count := s.count + 1; if s.count ___ 0 then VB(s.delay); VB(s.mutex) end; 42

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

View Full Document
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 s.count = -2 and s.mutex
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern