1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BaLLatris [955]
3 years ago
11

Use semaphore(s) to solve the following problem. There are three processes: P1, P2, and P3. Each process Pi has a segment of cod

es Ci, i=1, 2, 3. These three processes are executed only once, i.e., no repeat or loop at all, and their executions can start at any time. Your goal is to ensure that the execution of C1, C2, and C3 must satisfy the following conditions:
a. If C1 is executed ahead of C2 and C3, C2 must be executed ahead of C3.
b. Otherwise, C1 must be executed after both C2 and C3 are executed. In this case, the order of C2 and C3's execution doesn't matter. One of the possible execution orders is demonstrated below. Obviously, two other possible sequences in time are C2, C3, C1 and C3, C2, C1.
Please write your algorithm level code for semaphore initialization and usage in each code segment. [Hint: no if statements should ever be used. All you need is some semaphore function calls surrounding C1, C2, and C3 and their initial values.]
Computers and Technology
1 answer:
Lisa [10]3 years ago
4 0

Answer:

See explaination

Explanation:

Here we will use two semaphore variables to satisfy our goal

We will initialize s1=1 and s2=1 globally and they are accessed by all 3 processes and use up and down operations in following way

Code:-

s1,s2=1

P1 P2 P3

P(s1)

P(s2)

C1

V(s2) .

P(s2). .

. C2

V(s1) .

P(s1)

. . C3

V(s2)

Explanation:-

The P(s1) stands for down operation for semaphore s1 and V(s1) stands for Up operation for semaphore s1.

The Down operation on s1=1 will make it s1=0 and our process will execute ,and down on s1=0 will block the process

The Up operation on s1=0 will unblock the process and on s1=1 will be normal execution of process

Now in the above code:

1)If C1 is executed first then it means down on s1,s2 will make it zero and up on s2 will make it 1, so in that case C3 cannot execute because P3 has down operation on s1 before C3 ,so C2 will execute by performing down on s2 and after that Up on s1 will be done by P2 and then C3 can execute

So our first condition gets satisfied

2)If C1 is not executed earlier means:-

a)If C2 is executed by performing down on S2 then s2=0,so definitely C3 will be executed because down(s2) in case of C1 will block the process P1 and after C3 execute Up operation on s2 ,C1 can execute because P1 gets unblocked .

b)If C3 is executed by performing down on s1 then s1=0 ,so definitely C2 will be executed now ,because down on s1 will block the process P1 and after that P2 will perform up on s1 ,so P1 gets unblocked

So C1 will be executed after C2 and C3 ,hence our 2nd condition satisfied.

You might be interested in
WILL GIVEE BRAINLIEST ANSWER!!!!
Licemer1 [7]

Answer:

People have been ringing the death knell for email on and off for a few years now. But should we be listening?

The latest peal came from French IT company Atos, which declared that it would phase out internal emails by 2013. And for reasons we’ll all recongize: too much time spent dealing with too many emails, of which too few are useful and too many are spam. CEO Thierry Breton said his staff would instead use good old face-to-face communication, as well as instant messaging (IM) and social media tools.

3 0
3 years ago
Remembering on which continent 5 different countries are located
Illusion [34]

Answer:

South america.

Explanation:

8 0
3 years ago
When you open a browser window, it open in a _____. <br> a. fieldb. folderc. menud. window?
Romashka [77]
D. A window the rest are incorrect
4 0
3 years ago
How can an individual find career data?
kolezko [41]
How can an individual find career data?a. using a libraryb. searching the webc. conducting an interview with someone in a particular fieldd. all answer choices are sources for finding career data?The answer is d. An individual can do all the option a, b, and c to find a better career data.
6 0
3 years ago
Which smb share option should you enable if you don't want users to see files they don't have at least read permission to?
BigorU [14]
Enable all of them. have a nice day


5 0
3 years ago
Other questions:
  • The Freemont Automobile Factory has discovered that the longer a worker has been on the job, the more parts the worker can produ
    11·1 answer
  • What is connectivism and how does it apply to online learning?
    7·1 answer
  • What is the difference, if any, between an alpha test group and a beta test group? An alpha test group is made up of people asso
    9·1 answer
  • Linda subscribes to a cloud service. The service provider hosts the cloud infrastructure and delivers computing resources over t
    10·1 answer
  • What is a set of best practices that helps an organization to maximize the benefits of an information system, while at the same
    5·1 answer
  • A technician has been given a PC that is not powering up. After brief troubleshooting, the technician comes to the conclusion th
    14·1 answer
  • Assume that class BankAccount exists, and that it has a constructor that sets the private field balance, and that setBalance and
    13·1 answer
  • How can you stretch or skew an object in paint
    13·1 answer
  • Design algorithm and the corresponding flow chart for adding the subject score of 5, total value and rank.​
    14·1 answer
  • Which of the following is true about stateless applications?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!