edited by
1,740 views
4 votes
4 votes

mutex a = 1,b = 0;

For P(0):

while(1) {
       P(a);

       print(1);

       v(b);

}

For P(1):

while(1) {
       P(b);

       print(0);

       v(a);

}

Now obviously the output printed is 10101010.....

But my doubt is if they ask a regular expression for this question, then what would it be? $(10)*$ or $1 + (10)*$

So my question is will the semaphores always wakeup the process? Can I get a single $"1"$ ?

edited by

2 Answers

0 votes
0 votes

This can be considered under two conditions,

first

let there is only one process(or odd number of processes), then there are two possibilities that it might want to access code A or code B(this is process process synchronization problem not the critical section) and they can be accessed alternatively is the restriction, then the output could be either 1(or ending with one).

second

let there are even number of processes then there should be alternate 1's and 0's.

Now, the language of the code would be,

  • in terms of english(which is more precise here) -- every 0 is followed by a 1.
  • in terms of expression(it'll depend on number of processes) -- 1(01)* + (10)*
0 votes
0 votes
Answer will be given only after complete execution of both the processes ...so it will be (10)*

Related questions

0 votes
0 votes
1 answer
1
roopkathaaa asked Aug 25, 2023
1,183 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
2
Arbaz__Malik asked Dec 25, 2021
607 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 ...
6 votes
6 votes
1 answer
3
Shamim Ahmed asked Jan 13, 2019
1,424 views
Let S be a binary semaphore variable, S=0What will be the value of S when following operations are performed:-2P, 4V, 5P, 2P, 8V, 3P, 2V ?