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
Create a class that acts as a doubly linked list node. it should contain all the required data fields, at least 1 constructor, a
Zielflug [23.3K]

it is in Microsoft access


8 0
4 years ago
Use a while loop to repeatedly take input from the user and calculate a sum. The user will only be allowed to type in numbers, b
aev [14]

Answer and Explanation:

#take input from user

n = int(input("Enter any number: "))

#sum variable to store sum

sum=0

#condition to exit from loop

while n!=-999:

   #adding entered number in sum variable

  sum=sum+n

  #take input from user

  n = int(input("Enter any number : "))

#print the sum  

print("sum =",sum)

output:

Enter any number: 10

Enter any number : 100

Enter any number : -999

sum = 110

3 0
3 years ago
Question 9
Irina18 [472]

Answer:

Outsourcing

Explanation:

The boom in collaboration between U.S. companies and workforces in India created a need for Outsourcing.

I believe this is correct, but I'm not 100% certain.

8 0
2 years ago
THE DOMAIN IN AN EMAIL MESSAGE TELLS YOU THE
german
The domain in an email message tells you the type of service provider.

Hope this helped! :)
3 0
4 years ago
how risk can impact each of the seven domains of a typical IT infrastructure: User, Workstation, Local Area Network (LAN), Local
juin [17]

Answer and Explanation:

User Domain:

Risk

  • User can destroy the data and delete all User can find checked and use a password to delete all the work User can insert the USB flash and Infected CD.

Work Station Domain:

  • The workstation domain has some software vulnerability that connects remotely and steals data.
  • A workstation can fail because of lost data.

LAN domain

  • A worm can spread and infect the computer.
  • LAN have some known software vulnerability.
  • An unauthorized access of the organization workstation in

LAN WAN domain

  • LAN WAN domain that consists of internet and semi-private lines Service providers have major network problems.
  • Server can receive the DOS File Transfer protocol can allow uploaded illegal software.

LAN/WAN Domain

  • The boundary between the trusted and untrusted zones.
  • Hacker can penetrate the IT infrastructure and gain access.
  • Week ingress and egress filtering performance.
  • A firewall with the ports open can allow access to the internet.

System Storage Domain:

  • A fire can destroy the data DOC can cripple the organization's email.
  • A database server can be attacked by the injection of SQL and corrupting data.

Remote Access Domain

  • Communication circuit outage the connections
  • Remote communication from the office can be unsecured VPN tunneling between the remote computer and router
5 0
3 years ago
Other questions:
  • I need HELP ASAP! 30 POINTS to the RIGHT answer.
    12·2 answers
  • What is the purpose of a Program Epic?
    7·2 answers
  • Which answer best describes an unsubsidized federal loan
    13·1 answer
  • Raj’s computer just crashed and he lost most of his files. What should he do to avoid this problem in the future?
    10·2 answers
  • PLEASE HELP!!!
    12·1 answer
  • What types of projects require collaboration? en360
    15·1 answer
  • Which of the following activities would be best-suited for a thinking mind map?
    10·2 answers
  • Explain the correct ways of using keyboard. .​
    14·1 answer
  • What is a virus in a computer
    10·2 answers
  • Which of the following can be used to enter or display one complete row of information in a range or table without scrolling hor
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!