OS Questions and Answers - Classic Synchronization Problems

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

5) The dining - philosophers problem will occur in case of : a) 5 philosophers and 5 chopsticks b) 4 philosophers and 5 chopsticks c) 3 philosophers and 5 chopsticks d) 6 philosophers and 5 chopsticks

a) 5 philosophers and 5 chopsticks

ii) Suppose a process executes in the following manner (replacing signal with wait) : a) a deadlock will occur b) processes will starve to enter critical section c) several processes maybe executing in their critical section d) All of these

a) a deadlock will occur

2) In the bounded buffer problem, there are the empty and full semaphores that : a) count the number of empty and full buffers b) count the number of empty and full memory spaces c) count the number of empty and full queues d) None of these

a) count the number of empty and full buffers

6) A deadlock free solution to the dining philosophers problem: a) necessarily eliminates the possibility of starvation b) does not necessarily eliminate the possibility of starvation c) eliminates any possibility of any kind of problem further d) None of these

b) does not necessarily eliminate the possibility of starvation

4) To ensure difficulties do not arise in the readers - writers problem, _______ are given exclusive access to the shared object. a) readers b) writers c) None of these

b) writers

1) The bounded buffer problem is also known as: a) Readers - Writers problem b) Dining - Philosophers problem c) Producer - Consumer problem d) None of these

c) Producer - Consumer problem

7) All processes share a semaphore variable mutex, initialized to 1. Each process must execute wait (mutex) before entering the critical section and signal (mutex) afterward. i) Suppose a process executes in the following manner: Signal (mutex); ..... critical section ..... wait (mutex); In this situation : a) a deadlock will occur b) processes will starve to enter critical section c) several processes maybe executing in their critical section d) All of these

c) several processes maybe executing in their critical section

8) Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared Boolean variables S1 and S2 are randomly assigned. Method used by P1: while(S1==S2); Critical section S1 = S2; Method used by P2: while(S1!=S2); Critical section S2 = not(S1); Which of the following statements describes properties achieved? a) Mutual exclusion but not progress b) Progress but not mutual exclusion c) Neither mutual exclusion nor progress d) Both mutual exclusion and progress

d) Both mutual exclusion and progress

int itemCount = 0; procedure producer() { while (true) { 36 item = produceItem(); if (itemCount == BUFFER_SIZE) { sleep(); } putItemIntoBuffer(item); itemCount = itemCount + 1; if (itemCount == 1) { wakeup(consumer); } } } procedure consumer() { while (true) { if (itemCount == 0) { sleep(); } item = removeItemFromBuffer(); itemCount = itemCount - 1; if (itemCount == BUFFER_SIZE - 1) { wakeup(producer); } consumeItem(item); } } The problem with this solution is that it contains a race condition that can lead to a deadlock. Consider the following scenario: 1. The consumer has just read the variable itemCount , noticed it's zero and is just about to move inside the if block. 2. Just before calling sleep, the consumer is interrupted and the producer is resumed. 3. The producer creates an item, puts it into the buffer, and increases itemCount . 37 4. Because the buffer was empty prior to the last addition, the producer tries to wake up the consumer. 5. Unfortunately the consumer wasn't yet sleeping, and the wakeup call is lost. When the consumer resumes, it goes to sleep and will never be awakened again. This is because the consumer is only awakened by the producer when itemCount is equal to 1. 6. The producer will loop until the buffer is full, after which it will also go to sleep. Since both processes will sleep forever, we have run into a deadlock. This solution therefore is unsatisfactory. An alternative analysis is that if the programming language does not define the semantics of concurrent accesses to shared variables (in this case itemCount ) without use of synchronization, then the solution is unsatisfactory for that reason, without needing to explicitly demonstrate a race condition.

mbro


Ensembles d'études connexes

Chapter 11: Assessment and Care of Patients with Fluid and Electrolyte Imbalances

View Set

CH 23 OB newborn w/ special needs

View Set

The Parts of a Cell: Mastery Test

View Set

Chapter 8: Nutrition and Global Health

View Set