hw2sol

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

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

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(); ﬁllPot(); 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

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

View Full Document
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();
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
Ask a homework question - tutors are online