HW2.Solutions - (by calling the corresponding signal routine shared int lock = 0 Semaphore Sem = 1/Initialize count wait(Sem

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

View Full Document Right Arrow Icon
Homework Solutions Chapter 6 CS431, Fall 2005 6.4 Explain why spinlocks are not appropriate for single-processor systems yet are often used in multi-processor systems. My bad here. I did not catch the fact that the question itself is wrong. The only way spinlocks would not be appropriate on single processor systems is if they were not multi-programming systems (i.e., have no timer interrupts). Otherwise, they should work fine in either system. Please let me know if you lost any points on this question.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Answer: Initialize a semaphore to N, and perform a wait() operation before allowing a socket connection to be made and a signal() operation when a connection is closed. Once the number of active connections is greater than N, subsequent attempts to open a connection will block until a connection is released
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (by calling the corresponding signal() routine). shared int lock = 0 ; Semaphore Sem = 1 ; //Initialize count wait(Sem) { while(TestAndSet(lock)) ; //busy loop. Sem.count-- ; if (Sem.count < 0) { Place process on SemQ ; Block process and set lock to 0 } else lock = 0 ; } //signal routine on next page Signal(Sem) { while (TestAndSet(lock)) ; Sem.count++ ; if (Sem.count <= 0 ) { Remove process from SemQ; Place process on ready queue ; } lock = 0 ; } 6.27 Answer: • Using a semaphore, fix the race condition: Simply replace the variable available_resources with a semaphore and perform a wait() to decrement the number of resources and a signal() to increment the number of available resources....
View Full Document

This note was uploaded on 02/15/2010 for the course MGMT 201 taught by Professor Aacc during the Spring '10 term at Anne Arundel CC.

Page1 / 5

HW2.Solutions - (by calling the corresponding signal routine shared int lock = 0 Semaphore Sem = 1/Initialize count wait(Sem

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

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