OS questions and answeers - semaphores - 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

12) Each process Pi, i = 0,1,2,3,......,9 is coded as follows: repeat P(mutex) {Critical Section} V(mutex) forever The code for P10 is identical except that it uses V(mutex) instead of P(mutex). What is the largest number of processes that can be inside the critical section at any moment (the mutex being initialized to 1)? a) 1 b) 2 c) 3 d) None of these

c) 3 Explanation: Any one of the 9 processes can get into critical section after executing P(mutex) which decrements the mutex value to 0. At this time P10 can enter critical section by incrementing the value to 1. Now any of the 9 processes can enter the critical section by again decrementing the mutex value to 0. None of the remaining processes can get into their critical sections

2) The TestAndSet instruction is executed: a) after a particular process b) periodically c) atomically d) None of these

c) atomically

2) A semaphore : a) is a binary mutex b) must be accessed from only one process c) can be accessed from multiple processes d) None of these

c) can be accessed from multiple processes

10)The code that changes the value of the semaphore is: a) remainder section code b) non - critical section code c) critical section code d) None of these

c) critical section code

5) A binary semaphore is a semaphore with integer values : (choose two) a) 1 b) -1 c) 0 d) 0.5

a) 1 c) 0

4) The two atomic operations permissible on semaphores are : (choose two) a) wait b) stop c) hold d) signal

a) wait d) signal

8) Spinlocks are intended to provide __________ only. a) Mutual Exclusion b) Bounded Waiting c) Aging d) Progress

b) Bounded Waiting

1) What will happen if a non-recursive mutex is locked more than once ? a) Starvation b) Deadlock c) Aging d) Signaling

b) Deadlock Explanation: If a thread which had already locked a mutex, tries to lock the mutex again, it will enter into the waiting list of that mutex, which results in deadlock. It is because no other thread can unlock the mutex.

7) Semaphores are mostly used to implement : a) System calls b) IPC mechanisms c) System protection d) None of these

b) IPC mechanisms

1) An un-interruptible unit is known as : a) single b) atomic c) static d) None of these

b) atomic

3) The two kinds of semaphores are : (choose two) a) mutex b) binary c) counting d) decimal

b) binary c) counting

7) The wait operation of the semaphore basically works on the basic _______ system call. a) stop() b) block() c) hold() d) wait()

b) block()

4) A mutex : a) is a binary mutex b) must be accessed from only one process c) can be accessed from multiple processes d) None of these

b) must be accessed from only one process Explanation: P represents Wait and V represents Signal. P operation will decrease the value by 1 everytime and V operation will increase the value by 1 everytime.

9) If the semaphore value is negative : a) its magnitude is the number of processes waiting on that semaphore b) it is invalid c) no operation can be further performed on it until the signal operation is performed on it d) None of these

a) its magnitude is the number of processes waiting on that semaphore

6) The following pair of processes share a common variable X: Process A int Y; A1: Y = X*2; A2: X = Y; Process B int Z; B1: Z = X+1; B2: X = Z; X is set to 5 before either process begins execution. As usual, statements within a process are executed sequentially, but statements in process A may execute in any order with respect to statements in process B. ii) Suppose the programs are modified as follows to use a shared binary semaphore T: Process A int Y; A1: Y = X*2; A2: X = Y; signal(T); Process B int Z; B1: wait(T); B2: Z = X+1; X = Z; T is set to 0 before either process begins execution and, as before, X is set to 5. Now, how many different values of X are possible after both processes finish executing ? a) one b) two c) three d) four

a) one Explanation:The semaphore T ensures that all the statements from A finish execution before B begins. So now there is only one way in which statements from A and B can be interleaved: A1 A2 B1 B2: X = 11.

11)The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0. ProcessP0 while(true) { wait(S0); print'0' release(S1); release(S2); } ProcessP1 wait(S1); release(S0); ProcessP2 wait(S2); release(S0); How many times will P0 print '0'? a)At least twice b)Exactly twice 31 c)Exactly thirice d)Exactly once

a)At least twice

6) The main disadvantage of spinlocks is that : a) they are not sufficient for many process b) they require busy waiting c) they are unreliable sometimes d) they are too complex for programmers

b) they require busy waiting

8) The signal operation of the semaphore basically works on the basic _______ system call. a) continue() b) wakeup() c) getup() d) start()

b) wakeup()

6) The following pair of processes share a common variable X: Process A int Y; A1: Y = X*2; A2: X = Y; Process B int Z; B1: Z = X+1; B2: X = Z; X is set to 5 before either process begins execution. As usual, statements within a process are executed sequentially, but statements in process A may execute in any order with respect to statements in process B. i) How many different values of X are possible after both processes finish executing ? a) two b) three c) four d) eight

c) four Explanation: Here are the possible ways in which statements from A and B can be interleaved. A1 A2 B1 B2: X = 11 A1 B1 A2 B2: X = 6 A1 B1 B2 A2: X = 10 B1 A1 B2 A2: X = 10 B1 A1 A2 B2: X = 6 B1 B2 A1 A2: X = 12

3) Semaphore is a/an _______ to solve the critical section problem. a) hardware for a system b) special program for a system c) integer variable d) None of these

c) integer variable

5) Spinlocks are : a) CPU cycles wasting locks over critical sections of programs b) locks that avoid time wastage in context switches c) locks that work better on multiprocessor systems d) All of these

d) All of these

12)Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes: Process P1 : while(true) { w1 = true; while(w2 == true); Critical section w1 = false; } Remainder Section Process P2 : while(true) { 32 w2 = true; while(w1 == true); Critical section w2 = false; } Remainder Section Here, w1 and w2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct? a) It does not ensure mutual exclusion b) It does not ensure bounded waiting c) It requires that processes enter the critical section in strict alternation d) It does not prevent deadlocks, but ensures mutual exclusion

d) It does not prevent deadlocks, but ensures mutual exclusion


Conjuntos de estudio relacionados

Pharm Exam 3 - Drugs for Thyroid Disorders

View Set

AHT 3 - Cardiac Dysrhythmia - ATI, Lewis, Evolve. MOD 4- Exam 1

View Set

Google for Education Chrome Browser

View Set

Vocabulary Week 5: absolve, adamant, amiable, amoral, animosity, antagonist, encounter, epitome, malign

View Set