






















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























































l (^) Peterson’s solution l (^) using synchronization hardware l (^) semaphores l (^) monitors
l (^) producer-consumer and service-oriented system models l (^) exploit concurrent execution on multiprocessors
l (^) imperative to maintain data correctness
l (^) process run asynchronously, context switches can happen at any time l (^) processes may run concurrently l (^) different orders of updating shared data may produce different values
l (^) to coordinate updates to shared data l (^) order of process execution should not affect shared data
while (true){ /* wait if buffer full / while (counter == 10) ; / do nothing / / produce data / buffer[in] = sdata; in = (in + 1) % 10; / update number of items in buffer / R1 = load (counter); R1 = R1 + 1; counter = store (R1); } while (true){ / wait if buffer empty / while (counter == 0) ; / do nothing / / consume data / sdata = buffer[out]; out = (out + 1) % 10; / update number of items in buffer */ R2 = load (counter); R2 = R2 – 1; counter = store (R2); }
l (^) several processes concurrently manipulate shared data, and l (^) shared data value depends on the order of execution
R1 = load (counter); R1 = R1 + 1; R2 = load (counter); R2 = R2 – 1; counter = store (R1); counter = store (R2); Final Value in counter = 4! R1 = load (counter); R1 = R1 + 1; R2 = load (counter); R2 = R2 – 1; counter = store (R2); counter = store (R1); Final Value in counter = 6! Incorrect Sequence 1 Incorrect Sequence 2
l (^) mutual exclusion: only a single process can execute in its critical section at a time l (^) progress: selection of a process to enter its critical section should be fair, and the decision cannot be postponed indefinitely. l (^) bounded waiting: there should be a fixed bound on how long it takes for the system to grant a process's request to enter its critical section
l (^) structures for maintaining file systems, memory allocation, interrupt handling, etc.
l (^) process executing in kernel mode cannot be preempted l (^) disable interrupts when process is in kernel mode l (^) what about multiprocessor systems?
l (^) process executing in kernel mode can be preempted l (^) suitable for real-time programming l (^) more responsive
l (^) P0 and P1 can never be in the critical section at the same time l (^) if P0 does not want to enter critical region, P1 does no waiting l (^) process waits for at most one turn of the other to progress
do { flag[0] = TRUE; turn = 1; while (flag[1] && turn==1) ; // critical section flag[0] = FALSE; // remainder section } while (TRUE) do { flag[1] = TRUE; turn = 0; while (flag[0] && turn==0) ; // critical section flag[1] = FALSE; // remainder section } while (TRUE)
l (^) generalizing for more than two processes has been achieved
l (^) particularly for >2 processes
l (^) concurrent processes cannot be overlapped, only interleaved l (^) process runs until it invokes system call, or is interrupted
l (^) active process will run without preemption do { disable interrupts ; critical section enable interrupts ; remainder section } while(TRUE);
l (^) several processes share memory l (^) processors behave independently in a peer manner
l (^) too inefficient l (^) OS using this not broadly scalable
l (^) atomic test-and-set instruction l (^) atomic swap instruction l (^) atomic compare-and-swap instruction
int mutex; init_lock (&mutex) ; do { lock (&mutex); critical section unlock (&mutex) ; remainder section } while(TRUE); void init_lock (int *mutex) { *mutex = 0; } void lock (int *mutex) { while(TestAndSet(mutex)) ; } void unlock (int *mutex) { *mutex = 0; }
do{ waiting[i] = TRUE; key = TRUE; while(waiting[i] && key) key = TestAndSet(&lock); waiting[i] = FALSE; // Critical Section j = (i + 1) % n; while ((j != i) && !waiting[j]) j = (j+1) % n; if (j == i ) lock = FALSE; else waiting[j] = FALSE; // Remainder Section } while (TRUE); do{ waiting[i] = TRUE; key = TRUE; while(waiting[i] && key) key = TestAndSet(&lock); waiting[i] = FALSE; // Critical Section j = (i + 1) % n; while ((j != I) && !waiting[j]) j = (j+1) % n; if (j == i ) lock = FALSE; else waiting[j] = FALSE; // Remainder Section } while (TRUE);
do{ waiting[i] = TRUE; key = TRUE; while(waiting[i] && key) key = TestAndSet(&lock); waiting[i] = FALSE; // Critical Section j = (i + 1) % n; while ((j != i) && !waiting[j]) j = (j+1) % n; if (j == i ) lock = FALSE; else waiting[j] = FALSE; // Remainder Section } while (TRUE); do{ waiting[i] = TRUE; key = TRUE; while(waiting[i] && key) key = TestAndSet(&lock); waiting[i] = FALSE; // Critical Section j = (i + 1) % n; while ((j != I) && !waiting[j]) j = (j+1) % n; if (j == i ) lock = FALSE; else waiting[j] = FALSE; // Remainder Section } while (TRUE);