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
Which invention spurred the development of the digital camera?
Igoryamba

Answer:

B) The charge-coupled device

Explanation:

Around 1964 the first CMOS (Complementary Metal Oxide Semiconductor) circuits were developed. This would be the "embryo" of the Charge-coupled Device (CCD), which equips current digital cameras and who is responsible for capturing images.

CMOS is a small circuit that uses very little energy and stores information such as date, time and system configuration parameters.  

The first CCD was developed in 1969 and it is still used today in many portable devices and computers.

4 0
4 years ago
3. List three common vector image file types.
nika2105 [10]
Constructed using mathematical formulas rather than individual colored blocks, vector file types such as EPS, AI and PDF* are excellent for creating graphics that frequently require resizing.
8 0
3 years ago
An interface is a class that contains only the method headings and each method heading is terminated with a semicolon. True Fals
liubo4ka [24]

Answer:

False

Explanation:

Interfaces are similar to classes in Java, but they are not a type of class. A class defines the attributes and behaviours of objects, while interface contains the methods that shows the behaviours to be implemented by a class.

A method is one or more group of statements, it does not need to end with a semicolon. Methods in interfaces are abstract and for a class to contain these abstract method, it must be defined in the class.

3 0
3 years ago
When searching for your word processing file to finish writing your report, you should look for a file with which extension? (6
trasher [3.6K]

Answer:

doc

Explanation:

6 0
3 years ago
Which industry did the Interstate Commerce Act primarily affect? A. coal B. airplane C. steel D. oil E. railroad
babunello [35]

I believe the answer is E. Railroad, hope this helps!

6 0
4 years ago
Read 2 more answers
Other questions:
  • Suppose you want to delete an existing file from within Word. What would you do? A. Click on the File button, choose Recent, ope
    9·1 answer
  • Under what circumstances would it be appropriate to use the sentence method of note taking, and what are the advantages and disa
    7·2 answers
  • Mechanisms of evolution
    7·1 answer
  • The economist George gilder argued that
    6·1 answer
  • What allows user to double click with the mouse in a document to move the insertion point to a new location.?
    8·1 answer
  • Word processing software, spreadsheet software, database software, and presentation software are examples of what category of co
    6·1 answer
  • To adjust the margins on a page, users will navigate to the _____ tab.
    13·2 answers
  • Robert is leading a project online that includes students from different cultures. Two of the students spend most of the time li
    7·1 answer
  • Which database item would show details such as a customer’s name, their last purchase, and other details about a customer?
    11·2 answers
  • The formula in cell C9 is B9*F10. On copying this formula to cell Z9, what will be the formula​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!