●●● ●●●● 6.2 The Critical-Section Problem :: ●●●0 To solve the critical-section problem ●●●● o Criteria for the critical section problem solution Mutual exclusion(互斥) If process Pi is executing in its critical section, then no other processes can be executing in their critical sections of accessing the same shared data Progress(推进、空闲让进) If no process is executing in its critical section and there exist some processes that wish to enter their critical section The selection of the processes that will enter the critical section next cannot be postponed infinitely Bounded Waiting(有限等待) a bound must exist on the number of times for the processes waiting for entering their critical sections
12 6.2 The Critical-Section Problem ⚫ To solve the critical-section problem ⚫ Criteria for the critical section problem solution ⚫ Mutual Exclusion(互斥) ▪ If process Pi is executing in its critical section, then no other processes can be executing in their critical sections of accessing the same shared data. ⚫ Progress(推进、空闲让进) ▪ If no process is executing in its critical section and there exist some processes that wish to enter their critical section ▪ The selection of the processes that will enter the critical section next cannot be postponed infinitely. ⚫ Bounded Waiting(有限等待) ▪ A bound must exist on the number of times for the processes waiting for entering their critical sections
●●● ●●●● 6.2 The Critical-Section Problem::: ●●●● ●●●● General structure of process doi entry section critical section exit section remainder section 3 while(1)
13 6.2 The Critical-Section Problem ⚫ General structure of process Pi do { entry section critical section exit section remainder section } while (1);
●●● ●●●● 6.2 The Critical-Section Problem::: ●●●● critical section of producer ●●●● while(count = BUFFER SIZE); buffer [in]= nextProduced in=(in+ 1)% BUFFER SIzE, count++ critical section of consumer while(count ==0); nextconsumed= buffer[out out=(out +1% BUFFER_ SIZE count--:
14 6.2 The Critical-Section Problem critical section of producer while (count == BUFFER_SIZE); buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; critical section of consumer while (count == 0); nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--;
●●● ●●●● 6.2 The Critical-Section Problem::: ●●●0 o The critical sections in operating systems Race conditions in operating systems o At a time, many kernel-mode processes/threads may be active in the operating system The code implementing an oS kernel code is subject to several possible race conditions It is up to kernel developers to ensure that os is free from such race conditions
15 6.2 The Critical-Section Problem ⚫ The critical sections in operating systems ⚫ Race conditions in operating systems ⚫ At a time, many kernel-mode processes/threads may be active in the operating system ⚫ The code implementing an OS kernel code is subject to several possible race conditions ⚫ It is up to kernel developers to ensure that OS is free from such race conditions
●●● ●●●● 6.2 The Critical-Section Problem::: ●●●● o Two approaches to handle critical sections in Os o Non-preemptive kernels a kernel-mode process will run until it exits kernel mode, or blocks It is essentially free from race conditions on kernel data structures, as only one process is active in the kernel at a time Windows XP 2000, Traditional UNIX, Linux(prior to 2
16 6.2 The Critical-Section Problem ⚫ Two approaches to handle critical sections in OS ⚫ Non-preemptive kernels ▪ A kernel-mode process will run until it exits kernel mode, or blocks. ▪ It is essentially free from race conditions on kernel data structures, as only one process is active in the kernel at a time ▪ Windows XP/2000、Traditional UNIX、Linux (prior to 2.6)