408 views
0 votes
0 votes
Is it's possible for two process to execute P(s) and V(s) operation at the same time on a semaphore variable 's' , means if one process executed p(s) and at the same time another process executed v(s) simultaneously on the same semaphore variable ??

3 Answers

Best answer
1 votes
1 votes
"Same time" is a very controversial phrase in the question. If there is only one CPU then executing two instruction at the same time is not possible.

However in case of multiple CPU, theoretically, these instructions can be executed at the same time however, these operations P() and V() are hardware backed and atomic in nature. Hardware will make sure that they are executed serially. Order in which these instructions are executed is not defined.
selected by
0 votes
0 votes
No,cpu takes one process exec at a time but if n cpus then it can goto race condition i.e. cant say whether s=0 or s=2 assuming initial s=1

Related questions

0 votes
0 votes
1 answer
1
roopkathaaa asked Aug 25, 2023
1,185 views
In a certain application, the initial value of a counting semaphore s is 10. The following operations were completed on the semaphore in the given order 5P, 20P, 2V, 18P,...
0 votes
0 votes
0 answers
4
Arbaz__Malik asked Dec 25, 2021
608 views
given solution is wait(P) , wait(Q), wait(p) , wait(Q) for s1,s2,s3,s4 respectivelyI know this implementation is deadlock free just want to ask if it will follow bounded ...