Chapter 6/7 Synchronization Tools/Synchronization Examples Questions
7. The wait operation of the semaphore basically works on the basic _______ system call. a) stop() b) block() c) hold() d) wait()
block()
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) readers and writers d) none of the mentioned
writers
6. A binary semaphore is a semaphore with integer values : a) 1 b) -1 c) 0.8 d) 0.5
1
5. At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operations were completed on this semaphore. The resulting value of the semaphore is : (GATE 1987) a) 42 b) 2 c) 7 d) 12
2
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 the mentioned
3
4. The following three conditions must be satisfied to solve the critical section problem : a) Mutual Exclusion b) Progress c) Bounded Waiting d) All of the mentioned
All of the mentioned
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 the mentioned
All of the mentioned
11. The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0. Process P0 while(true){ wait(S0); print '0'; release(S1); release(S2); } Process P1 wait(S1); release(S0); Process P2 wait(S2); release(S0); How many times will P0 print '0' ? a) At least twice b) Exactly twice c) Exactly thrice d) Exactly once
At least twice
9. 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. (GATE 2010) 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
Both mutual exclusion and progress
10. Spinlocks are intended to provide __________ only. a) Mutual Exclusion b) Bounded Waiting c) Aging d) Progress
Bounded Waiting
1. What will happen if a non-recursive mutex is locked more than once ? a) Starvation b) Deadlock c) Aging d) Signaling
Deadlock
The transactional memory mechanism for process synchronization facilitates what software development approach to guaranteeing atomicity?
Declarative
9. Semaphores are mostly used to implement : a) System calls b) IPC mechanisms c) System protection d) None of the mentioned
IPC mechanisms
13. 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) { 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
It does not prevent deadlocks, but ensures mutual exclusion
1. The bounded buffer problem is also known as : a) Readers - Writers problem b) Dining - Philosophers problem c) Producer - Consumer problem d) None of the mentioned
Producer - Consumer problem
8. 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. Suppose a process executes in the following manner : wait(mutex); ..... critical section ..... wait(mutex); 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 the mentioned
a deadlock will occur
6. Bounded waiting implies that there exists a bound on the number of times a process is allowed to enter its critical section : a) after a process has made a request to enter its critical section and before the request is granted b) when another process is in its critical section c) before a process has made a request to enter its critical section d) none of the mentioned
after a process has made a request to enter its critical section and before the request is granted
1. An un-interruptible unit is known as : a) single b) atomic c) static d) none of the mentioned
atomic
2. The TestAndSet instruction is executed : a) after a particular process b) periodically c) atomically d) none of the mentioned
atomically
3) The two kinds of semaphores are : a) mutex & counting b) binary & counting c) counting & decimal d) decimal & binary
binary & counting
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 the mentioned
can be accessed from multiple processes
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 the mentioned
count the number of empty and full buffers
3. The segment of code in which the process may change common variables, update tables, write into files is known as : a) program b) critical section c) non - critical section d) synchronizing
critical section
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 the mentioned
critical section code
1. Concurrent access to shared data may result in : a) data consistency b) data insecurity c) data inconsistency d) none of the mentioned
data inconsistency
3. In the bounded buffer problem : a) there is only one buffer b) there are n buffers ( n being greater than one but finite) c) there are infinite buffers d) the buffer size is bounded
there are n buffers ( n being greater than one but finite)
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 the mentioned
does not necessarily eliminate the possibility of starvation
8. In the bakery algorithm to solve the critical section problem : a) each process is put into a queue and picked up in an ordered manner b) each process receives a number (may or may not be unique) and the one with the lowest number is served next c) each process gets a unique number and the one with the highest number is served next d) each process gets a unique number and the one with the lowest number is served next
each process receives a number (may or may not be unique) and the one with the lowest number is served next
5. Mutual exclusion implies that : a) if a process is executing in its critical section, then no other process must be executing in their critical sections b) if a process is executing in its critical section, then other processes must be executing in their critical sections c) if a process is executing in its critical section, then all the resources of the system must be blocked until it finishes execution d) none of the mentioned
if a process is executing in its critical section, then no other process must be executing in their critical sections
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
they require busy waiting
7. 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. How many different values of X are possible after both processes finish executing ? a) two b) three c) four d) eight
four
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 the mentioned
integer variable
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 the mentioned
its magnitude is the number of processes waiting on that semaphore
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 the mentioned
must be accessed from only one process
8. The program 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
one
2. A situation where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which access takes place is called : a) data consistency b) race condition c) aging d) starvation
race condition
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. 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 the mentioned
several processes maybe executing in their critical section
7. A minimum of _____ variable(s) is/are required to be shared between processes to solve the critical section problem. a) one b) two c) three d) four
two
4. The two atomic operations permissible on semaphores are : a) wait b) stop c) hold d) none of the mentioned
wait
8. The signal operation of the semaphore basically works on the basic _______ system call. a) continue() b) wakeup() c) getup() d) start()
wakeup()
What are the general hardware instructions that can be performed atomically?
→test_and_set →compare_and_swap