Question

NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! give the wait and...

NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS!
give the wait and signal algorithms for counting semaphores. How are semaphores used to protect a critical region? how can message passing be used instead to protect critical regions?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

struct semaphore
{
   int value;
   Queue type L;
}

Wait (semaphore s)
{
   s.value = s.value - 1;
   if (s.value < 0)
   {
      put process (PCB) in L;
      sleep();
   }
   else
      return;
}

Signal (semaphore s)
{
   s.value = s.value + 1;
   if (s.value <=0 )
   {
       select a process (PCB) from L;
       wake up();
   }
}

2)

  • Binary Semaphores : They can only be either 0 or 1. They are also known as mutex locks, as the locks can provide mutual exclusion. All the processes can share the same mutex semaphore that is initialized to 1. Then, a process has to wait until the lock becomes 0. Then, the process can make the mutex semaphore 1 and start its critical section. When it completes its critical section, it can reset the value of mutex semaphore to 0 and some other process can enter its critical section.
  • Counting Semaphores : They can have any value and are not restricted over a certain domain. They can be used to control access a resource that has a limitation on the number of simultaneous accesses. The semaphore can be initialized to the number of instances of the resource. Whenever a process wants to use that resource, it checks if the number of remaining instances is more than zero, i.e., the process has an instance available. Then, the process can enter its critical section thereby decreasing the value of the counting semaphore by 1. After the process is over with the use of the instance of the resource, it can leave the critical section thereby adding 1 to the number of available instances of the resource.

3)

Several methods exist for implementing mutual exclusion with message passing. One method uses processes to regulate access to shared resources. A resource control process has a variable which records the status of a resource (free or busy), and a buffer which contains request messages from other processes.

This pictures shows an interaction between a process that wants to access a shared resource, and a resource control process. Three messages are sent here. Message (1) is a request for access to the resource. Process P1 then blocks, waiting for a reply from the resource control process. Message (2) is the reply sent by the control process. This message wakes up P1, and P1 now uses the resource. Message (3) informs the resource control process that P1 is done using the resource.

The code for this interaction looks like this:

P1:

send(control_process, "Give me resource");

receive(control_process, Message); // block while waiting for a reply

  
       {
        ...Critical Section...
       }

send(control_process, "Done with resource");

Add a comment
Know the answer?
Add Answer to:
NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! give the wait and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! in openGL given a...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! in openGL given a pixel represented as a triple float color values (0.3,0.5,0.8) convert the pixel to byte color values . Note the range of a byte color value is [0,255] and the range of a float color is [0.0,1.0]. Round answer to the nearest whole number

  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! A) write a regular...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! A) write a regular expression (use regular expression syntax) to represent a floating point number, where the number begiywith an optional sign followed by at least 1 digit , followed by a decimal point and one or more other digits. Ex: -33.9 , +1.11919, 1.0 B) draw a dfsa to represent the regular expression

  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY The time taken to execute a given task for A B a...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY The time taken to execute a given task for A B and C are: A- 10m , 25 s B - 8m , 40s C - 6m, 30s what is the performance of B and C relative to A?

  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! JAVA C) Write a...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! JAVA C) Write a code to define/ derive a new subclass named superVillan. The SuperVillan object has an objective (like world domination- string) and a nemesis (SuperHero) Add these attributes to the sub class. write proper cinstructor I: Programming rhe following code segment w segment will be used in the epresents a superhero be used in the next two ques blic class Superhero ( private final string private...

  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! MULTIPLE CHOICE no explanation...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! MULTIPLE CHOICE no explanation needed SPRING Cs 424-524 aUESTION 1 12 points each, 30 points total +2 extra) Multiple 1. The main reason to include enumeration types in a programming language is to TEST2 choice: circle or check the best answer a. Make programs run faster b. Improve program readability c. Eliminate unnecessary /O d. Reduce type errors 2. A C++ value parameter is an example of a....

  • NEED ASAP WILL RATE RIGHT AWAY Construct a truth table and state if the expression is...

    NEED ASAP WILL RATE RIGHT AWAY Construct a truth table and state if the expression is a tautology , contradiction or neither: (P -> Q) ^ (Q -> R) -> (P -> R)

  • Hi, I need this answered ASAP. I will give you a good rate. Please make sure...

    Hi, I need this answered ASAP. I will give you a good rate. Please make sure you draw the 'LOL Chart'. Thank you. Question 9 20 pts A pinball machine consists of a spring that is compressed to fire a small ball into the game. How fast is the 5.1 g ball moving when a spring with a k value of 40 N/m is compressed 15 cm? Draw the LOL Chart and solve the problem.

  • I need both parts done ASAP, this is for communications and systems 1. please show all...

    I need both parts done ASAP, this is for communications and systems 1. please show all work and label what you are do I g so I can understand it please 1) (20 points) Message signal, m (t) 0.8 cos(2π250), is used to modulate carrier signal, c(t) to produce output y(t). Carefully label your plots: 1.5 co (2π5000t). la) (5 points) Assuming coherent modulation, plot yit)

  • Hey guys please give me the answers quickly I need it so quick I will give you a good rate thank you 11. For the rea...

    Hey guys please give me the answers quickly I need it so quick I will give you a good rate thank you 11. For the reaction, 2 SO2(g) + O2(g) - 2 SO3(g), at 450.0 K the equilibrium constant, Kc, has a value of 4.62. A system was charged to give these initial concentrations: (SO3) = 0.0254 M, [O2) = 0.00855 M. (SO2) = 0.500 M. In which direction will it go? a. to the right b. to the left...

  • I need this answered correctly ASAP. Please make sure to do all parts. If answers are...

    I need this answered correctly ASAP. Please make sure to do all parts. If answers are incorrect I will give you a bad rate. Thank you. Question 16 10 pts A mass of 7 kg attached to a vertical spring stretches the spring 7 cm from its original equilibrium position. • What is the spring constant? • What is the period of motion of the system? • What is the frequency of the motion?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT