hw2sol - HW 2 SOLUTIONS (1) Solution to Orphan problem:...

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

View Full Document Right Arrow Icon
HW 2 SOLUTIONS (1) Solution to Orphan problem: Semaphore empty = new Semaphore(0); Semaphore mutex = new Semaphore(1); Semaphore cook = new Semaphore (0); integer M = MAX CAPACITY; integer S = M; procedure ORPHAN CODE while true do mutex.P(); if S == 0 then cook.V(); empty.P(); end if S = S - 1; mutex.V(); eat(); end while end procedure procedure COOK CODE while true do cook.P(); S = M; empty.V(); fillPot(); end while end procedure (2) Semaphore mutex = new Semaphore(1); Semaphore listSem = new Sempahore(1); Semaphore insertMutex =new Semaphore(1); integer active = 0; procedure SEARCHER THREAD while true do mutex.P(); active = active +1; if active == 1 then listSem.P(); end if 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 HW 2 SOLUTIONS mutex.V(); search(); mutex.P(); active = active -1; if active == 0 then listSem.V(); end if mutex.V(); use data(); end while end procedure procedure INSERTER THREAD while true do insertMutex.P(); mutex.P(); active = active +1; if active == 1 then listSem.P();
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 04/02/2012 for the course CIS 486 taught by Professor Mcsweeney during the Spring '10 term at Syracuse.

Page1 / 4

hw2sol - HW 2 SOLUTIONS (1) Solution to Orphan problem:...

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