{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW2.Solutions - (by calling the corresponding signal...

Info icon This 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.
Image of page 1

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

View Full Document Right 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
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern