Two approaches used to handle critical sections in

This preview shows page 6 - 10 out of 39 pages.

Two approaches, used to handle critical sections in operating systems: " Nonpreemptive kernels : $ Does not allow a process running in kernel mode to be preempted. $ Is thus free from race conditions on kernel data structures, as only one process is active in the kernel at a time. " Preemptive kernels : $ Allow a process to be preempted while it is running in kernel mode. $ The kernel must be carefully designed to ensure that shared kernel data are free from race conditions.
Image of page 6

Subscribe to view the full document.

Synchronization 7 13 The Critical-Section Problem (cont’d) ! Why preferring preemptive kernel? " Less risk that a kernel-mode process will run for an arbitrarily long period. " Allow a real-time process to preempt a process currently running in the kernel. ! Windows XP and Windows 2000 are nonpreemptive kernels. ! Several commercial versions of UNIX (including Solaris and IRIX) and Linux 2.6 kernel (and the later version) are preemptive. 14 Peterson’s Solution ! A software-based solution to the critical-section problem. ! Is restricted to two processes that alternate execution between their critical section and remainder sections. " The processes are numbered P 0 and P 1 , or P i and P j . ! The method requires two data items to be shared between the two processes: int turn; Boolean flag[2]; " The variable turn indicates whose turn it is to enter the critical section. " The flag array is used to indicate if a process is ready to enter the critical section. $ flag[i] = true implies that process P i is ready!
Image of page 7
Synchronization 8 15 Peterson’s Solution (cont’d) ! The Peterson’s solution for process P i . ! If both processes try to enter at the same time " turn will be set to both i and j at roughly the same time. " The eventual value of turn decides which can go. do { flag[i] = TRUE; turn = j; while ( flag[j] && turn == j); CRITICAL SECTION flag[i] = FALSE; REMAINDER SECTION } while (TRUE); 16 Peterson’s Solution (cont’d) ! To prove the method is a solution for the critical-section problem, we need to show: 1. Mutual exclusion is preserved. " P i enters its critical section only if either flag[j]==false or turn==i . " If both processes want to enter their critical sections at the same time, then flag[i] == flag[j] == true . " However, the value of turn can be either 0 or 1 but cannot be both . " Hence, one of the processes must have successfully executed the while statement (to enter its critical section) , and the other process has to wait, till the process leaves its critical section. # mutual exclusion is preserved .
Image of page 8

Subscribe to view the full document.

Synchronization 9 17 Peterson’s Solution (cont’d) 2. The progress requirement is satisfied. " Case 1: $ P i is ready to enter its critical section. $ If P j is not ready to enter the critical section (it is in the remainder section). $ Then flag[j] == false , and P i can enter its critical section. " Case 2: $ P i and P j are both ready to enter its critical section.
Image of page 9
Image of page 10
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung
  • producer, monitor

{[ 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