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
The _______ number system allows digital devices to represent virtually any number simply by using 0s and 1s.
Mashcka [7]
Binary number system. With n bits you can create 2^n numbers.
6 0
3 years ago
10 facts about turbines
sp2606 [1]
They provide wind energy
 Wind power consists of turning energy from the wind to other energy forms.
Windmills have been in use since 2000 B.C.
developed in Persia
Wind energy is the fastest growing mode of electricity
Wind farms can be constructed in off shore locations
Wind energy is renewable and pollution free source of energy
Most of the modern wind turbines have 3 blades
The largest wind turbine in the world is located in US in Hawaii
The first modern wind turbine was built in 1940’s in Vermont.
8 0
3 years ago
Read 2 more answers
What is the main storage device where the computer stores data?
Fudgin [204]
D. RAM
<span>Primary storage typically refers to random access memory (RAM), while secondary storage refers to the computer's internal hard drive. RAM, commonly called "memory," is considered primary storage, since it stores data that is directly accessible by the computer's CPU.</span>
8 0
3 years ago
The 2 main types of copyright relevant to the recording industry?
Aleksandr-060686 [28]
The two main types are Manuscript copyright and Musical composition copyright.
<span>

</span>
4 0
3 years ago
Read 2 more answers
You can find synonyms and disciplinary jargon in the ______, _______, and ______ in your search results. You can then use these
Slav-nsk [51]

Answer:

1. Title

2. Abstract

3. Subject Headings

Explanation:

To carry out a project or research survey, a researcher needs an appropriate title that satisfies the technical keywords relating to the content and expected outcome of the research.

Hence, in this case, to find an appropriate title for a research survey "You can find synonyms and disciplinary jargon in the TITLE, ABSTRACT, and SUBJECT HEADINGS in your search results. you can then use these as keywords in additional searches."

7 0
3 years ago
Other questions:
  • Due to the internal style sheets of some browsers, your website may look different to someone who is using firefox as opposed to
    11·1 answer
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • A user makes a request to implement a patch management service for a company. As part of the requisition the user needs to provi
    7·1 answer
  • Write a Java program that prompts the user for an int n. You can assume that 1 ≤ n ≤ 9. Your program should use embedded for loo
    5·1 answer
  • Why is it so important to have employees who can critically think?
    7·2 answers
  • Mention two strategies of collecting data​
    13·1 answer
  • Superclass in python explanation
    7·1 answer
  • Justify any FOUR significant factors to remember when installing your motherboard
    7·1 answer
  • I need help about computer program. Solve C language code...... please​
    7·1 answer
  • Brainliest For Tascake Because People Texted Before Tascake Could<br><br> Hurry Tascake
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!