You are on page 1of 13
Drees Counting Semaphores Questions Tea nae Start Complete Exam Preparation Reman K cero Peas arc ct Poeccey Download App MCQ Question 1 View this Question Online At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operation were completed on this semaphore. The resulting value of the semaphore is 1. 42 ‘Answer (Detailed Solution Below) Option 2:2 | Counting Semaphores MCQ Question 1 Detailed Solution Concepts: V(S): Signal operation will increment the semaphore variable, that is, St+. P(S): Wait operation will decrement the semaphore variable, that is, S—. Data: Initial counting semaphore =| = 7 Wait operation = 20 P Signal operation = 15 V Final counting semaphore = F Formula: F=1+15V420P Calculation: F=7+15(+1) + 20(1) oFe2 the resulting value of the semaphore is 2 nee arty etna) Start Complete Exam Preparation RAR st Daily Li fara Mock Tests rhe es ra Goa ror Download App MCQ Question 2 View this Question Online At a particular time of computation, the value of a counting semaphore Is 7. Then 20 P operation and x V operations were completed on this semaphore. If the final value of the semaphore is 5, x will be 1.18 Answer (Detailed Solution Below) Option 1:18 Counting Semaphores MCO Question 2 Detailed Solution Concepts: \V(S): signal operation will increment the semaphore variable, that is, S++. P(S): wait operation will decrement the semaphore variable, that is, S-. Data: Initial counting semaphore (1) = 7 Signal operation = x V Wait operation = 20 P Final counting semaphore (F) = 5 Calculation: 5=7+xV+20P 5=7+x (+1) +20 (1) x=5-7+20 ok=18 & India's #4 Learning Platform ere acta Start Complete Exam Preparation Pee Teac Decrees & Quizzes Download App MCQ Question 3 View this Question Online Each of a set of n processes executes the following code using two semaphores a and b initializedto 1 and 0, respectively. Assume that count is a shared variable initializedto 0 and not used in CODE SECTION P. CODE SECTION P wait (a); count=count+1 ; if (count==n) signal (b) ; signal (a) ; wait (b) ; signal (b) ; CODE SECTION Q What does the code achieve? 1. It ensures that no process executes CODE SECTION Q before every process has finished CODE SECTION P. 2. ft ensures that at most two processes are in CODE SECTION Q at any time. 3. It ensures that all processes execute CODE SECTION P mutually exclusively. 4. It ensures that at most n-1 processes are in CODE SECTION P at any time. Answer (Detailed Solution Below) Option 1 : It ensures that no process executes CODE SECTION Q before every process has finished CODE SECTION P_ Counting Semaphores MCQ Question 3 Detailed Solution Explanation: The key statement in the above code Is wait (b). It will keep the remaining processes blocked until value on count becomes n. Once, the value of count = n, signal (b) would be executed and then a process can enter the code section Q. Thus, none of the process will execute Q until every process has executed code section P. Stepwise Explanation: Initialization: a=1, b=0, count= 0 There are n processes say, Py, P2, Pa, ....usesPh. Let's assume P1 has executed successfully the code section P and encounters the statements: wait (a); Now, ‘a’ becomes 0, so all the subsequent processes are blocked. b= 0, count= 0. count=count+l ; [a=0, b=0, count=1] if (count==n) signal (b) ; [if condition not true, so statement will not be executed] signal (a); [a= 1, b=0, count= 1. Other processes can now execute Wait(a)] wait (b) ; , therefore P1 also gets blocked and statement would not be executed] signal (b); This statement would only run if its preceding statement is executed, which in turn would only be executed if (count==n), Therefore, none of the process would execute Q until every process has successfully executed code section P. & ear cn Cae are Sela merle) (cM ec deh) Peers fared Dor cia Que: Download App MCQ Question 4 View this Question Online The producer and consumer processes share the following variables: Intn, Semaphore M=1 Semaphore E=n Semaphore F=0 The consumer process must execute and before removing an item from buffer. 1. signal(M), signal(F) 2. signal(M), wait(F) 3. Signal(F), wait(M) 4. wait(F), wait(M) Answer (Detailed Solution Below) Option 4: wait(F), wait(M) Counting Semaphores MCQ Question 4 Detailed Solution Concept: In producer- consumer problem, producer can only produce the items when there is space in the buffer, means it has to wait for the consumer to consume the items. Similarly, consumer can consume the item only when producer produces it Explanation: Given, M= 1, E=nandF =0 Here, semaphore M is for mutual exclusion, semaphore E is for empty space in buffer , semaphore F is used to define the space filled by the producer. code for producer side: while (true) { Produce() Waitt) Wait(M) Append() Signal(M) Signal(F) } Code for consumer side: while(true) { Wait(F) Wait(M) Consume() Signal(M) Signal(E) } rl india’s #1 Learning Platform Start Complete Exam Preparation Deere radars ead >) Mock Tests force Cesena exten Download App MCQ Question 5 View this Question Online Consider a non-negative counting semaphore S. The operation P(S) decrements S, and V(S) increments S. During an execution, 20 P(S) operations and 12 V(S) operations are issued In some order. The largest initial value of S for which at least one P(S) operation will remain blocked is___. Answer (Detailed Solution Below) 7 Counting Semaphores MCQ Question 5 Detailed Solution Concepts: V(S): Signal will wees ‘the semaphore variable, that Is, St. P(S): Signalwill decrement the semaphore variable, that is, S— Data: Initial counting semaphore = x Signal operation = 12 V Wait operation = 20 P Since at least 1 process in blocked state Final counting semaphore (F} Formula: Fex+20P+12V Calculation: 2x4 20(1) +12(+1) oKs7 Therefore, largest value of initial semaphore count is 7 ee enc Start Complete Exam Preparation aes fale MasterClasse: Question Bank Download App MCQ Question 6: View this Question Online > [ Ree ars Consider a counting semaphore S. The operation P(S) performs the operation --S and operation V(S) perform the operation ++V. During program execution, 17P and 11V operation Is performed in the some order. What is the smallest initial value of S for which at most 4 processes are in the blocked state? Answer (Detailed Solution Selow) 2 Counting Semaphores MCQ Question 6 Detailed Solution Concepts: V(S): Signalwill increment the semaphore variable, that is, S++. P(S): Signal will decrement the semaphore variable, that is, S— Data: Initial counting semaphore = x ‘Signal operation = 11 V Wait operation = 17 P Since at most 3 process in blocked state Final counting semaphore (F) = -4 Formula: Fex+17P+11V Calculation: ext 17(4) #1141) exe? «smallest value of initial semaphore count is 2 & eee a arc - Start Complete Exam Preparation eRe Puts Practice ead ei Loner Coreen Download App MCQ Question 7: View this Question Online > Consider a non-negative counting semaphore S. During an execution, 16P (wait) operations, and 4V (signal) operations are issued In some order. The largest Initial value of S for which at least three up operations will remain blocked is__. Anewer (Detailed Solution Below) 9 Counting Semaphores MCQ Question 7 Detailed Solution After each wait operation, the semaphore value decrenented by 1 and after the signal operation, the semaphore value incremented by 1. Consider the initial value of the semaphore be X. X-16+4=-3 X-12=3 X=9 Reeveat rte "pee Start Complete Exam Preparation pats) Caer: oor kes Corres Download App MCQ Question 8: View this Question Online> At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operation were completed on this semaphore. The resulting value of the semaphore is 1, 42 5. None of above Answer (Detailed Solution Below) Option 2:2 Counting Semaphores MCQ Question 8 Detailed Solution Concepts: \(S): Signal operation will increment the semaphore variable, that is, S++. P(S): Wait operation will decrement the semaphore variable, that is, S- Data: Initial counting semaphore Wait operation = 20 P Signal operation = 15 V Final counting semaphore = F Formula: F=|+15V+20P Calculation: F=7+15(+1) + 20(1) ah? the resulting value of the semaphore Is 2 ree arr pee oliul Start Complete Exam Preparation aeons elicins Reta Download App MCQ Question 9: View this Question Online > Which of the following interprocess communication model is used to exchange messages among co-operative processes? aa ett 1. Sharedmemory model 2. Message passing model 3, Shared memory and message passing model 4. Queues q Answer (Detailed Solution Below) Option 3: Shared memory and message passing model Counting Semaphores MCQ Question 9 Detailed Solution Concept: Inter process communication (IPC) is a mechanism which allows processes to communicate with each other end synchronize their actions. By maintaining this type of communication, processes aré said to so-operate with each other. Processes can communicate with each other using these two ways: - Shared Memory - Message passing & Pn ra eal cn Sela merle cee hol) Erol ca Dor cree ownload App MCQ Question 10: View this Question Online > Consider a shared variable with an initial value 5, this shared variable is used by four concurrent processes A, B, C, and D. Process A reads the shared variable and increment it by two, and process B reads the shared variable and decrement it by three before writing it to the memory. Process C reads the shared variable and decrement it by one while process Dreads the shared variable and increment it by two before writing it to the memory. All the processes before reading the value perform wait operation on a counting semaphore variable S with initial value 2 and after writing it to the memory, the signal operation is performed before the processes get terminated. Find the maximum possible value of the shared variable in the memory? Answer (Detailed Solution Below) 9 Counting Semaphores MCQ Question 10 Detailed Solution Concepts: V(S): Signal will increment the semaphore variable, that is, S++. P(S): Signalwill decrement the semaphore variable,, that is, S-. Data: Shared variable = x= 5 Counting semaphore = S = 2 Process A’ Procass B: Process C: | Process D: »(S) PG) PS) PG) ro) 108) 109) 3) x=xX+2 x=x-3 x=X-1 x=xt2 wn) 7) w(e) rr) vs) ws) v(s) vs) exit(A) exit(B) exit(C) exit(D) Calculation: if Process Ais executed completely x542-7 S=2 Process D reads the value and increment it by 2 x=7#2=9 S=1 Note that still process D doesn't write it to memory If Process Bis executed completely x=7-3-4 S=1 If Process Cis executed completely x=4-1=3 S=1 Now, D writes the valuex = 9 ~. maximum possible value is 9.

You might also like