Question

Consider the following three threads and four semaphores: /Initialize x / x = 1; /Initialize semaphores/ s1 = s2 = s3 = s4 = void threadl () void thread2) void thread3 () while (x != 5400) while (x != 5400) while (x != 5400) x=x*2; x=x*3; x=x*5; exit (0)i exit (0) exit (0) Provide initial values for the four semaphores and add PO, VO semaphore operations (using the four semsphores) in the code for dhread , 2 c that the processuaraneed lo terinateneed answer for this question please explain in detail. Appreciate it! thank you so much!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I am taking semaphore values as below

      S1 = 1 , S2 = 0 , S3 = 0 , S4 = 1

with this intial conditions we are making only thread 1 to execute 1st

so we are taking S1 = 1 for thread 1 and S2 = 0 , S3 = 0 for threads 2 and 3.

we are making S4 common for all threads if it is 1 then only they can access x.

Now after thread1 execution it will up S2 so that thread1 can run after thread1

and after thread2 execution it will up S3 so that thread3 can run after thread2.

void thread1() {

    while (x != 5400){

          P(S1);

          P(S4);

           x = x * 2;

         V(S4);

         V(S1);

         V(S2);

    }

}

void thread2() {

    while (x != 5400){

          P(S2);

          P(S4);

           x = x * 2;

         V(S4);

         V(S2);

         V(S3);

    }

}

void thread3() {

    while (x != 5400){

          P(S3);

          P(S4);

           x = x * 5;

         V(S4);

         V(S3);

    }

}

Add a comment
Know the answer?
Add Answer to:
need answer for this question please explain in detail. Appreciate it! thank you so much! Consider...
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
  • operating system engineering , please read the question and solve on the given skeleton code ....

    operating system engineering , please read the question and solve on the given skeleton code . Write a multi-threaded program with Semaphores as counters and pthread_mutex_t mutex to solve the producer-consumer problem: A bounded buffer is simply a global integer array of size N (2) which can be accessed by multiple threads. • Create two types of threads - Producer (2) and Consumer (2). Producers will write to the buffer, and the consumers will read the buffer. In this scenario,...

  • If you could please answer 8.1 & 8.2 that would be incredible. Thank you so much....

    If you could please answer 8.1 & 8.2 that would be incredible. Thank you so much. 8.1. To show xn 2 Xn+1 for n 2 N and to find the value of N EN, consider the function. f: (0, +00) → R and so f(t) = n) Observe that if we restrict the domain of f to N then f(n) = n(n) = xn Therefore, if f is decreasing, then as will {xn} be decreasing. This suggests using methods from...

  • please answer this asap i need this to bump up my grade! thank you so much...

    please answer this asap i need this to bump up my grade! thank you so much i really appreciate it. Solve each of the following trigonometric equations over the given Total: 22 marks domains. SHOW YOUR WORK and make sure that your solutions are clearly indicated, either in exact values in terms of 2 or in degrees (depending on the given domain). When finished, submit your assignment to your instructor. a) sec 0 = - 2, 0<< 360° b) cos...

  • Please answer in Java. The code that needs to be modified is below. Thank you. Question:...

    Please answer in Java. The code that needs to be modified is below. Thank you. Question: Implement Doubly Linked List add method which add an element to a specific position. - It’s an instance method that takes a position and an element, then adds the element to this specific position and shifts the element currently at this position and any subsequent elements to the right. It throws an exception if the position is out of bound. It traverses the list...

  • Please chose the right answer and explain why. Thank you so much! Question 5 1 pts...

    Please chose the right answer and explain why. Thank you so much! Question 5 1 pts Suppose that the government mandates a minimum wage, as shown in the graph below. How many unemployed workers will there be in this market with the minimum wage? (in millions) Wage Rate ($/hour) Labor Market Supply of Labor Minimum wage 2- > 131 X Demand for Labor 1.7 2 2.4 Quantity (Number of Workers, Millions) Question 6 1 pts The graph below illustrates a...

  • please help and answer all ASAP please thank you so much Question 49 (1 point) When...

    please help and answer all ASAP please thank you so much Question 49 (1 point) When light travelling in glass enters glass with a higher index of refraction, the wave will be: a) partially transmitted with a change in phase b) transmitted forming a standing wave pattern in air c) reflected so as to form a node at the junction d) totally reflected at the junction e) partially reflected without a change in phase Question 38 (1 point) The charge,...

  • Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(...

    Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(char *s) {    /* this is here so code compiles */ return 0; } /* array version */ /* concantenate t to the end of s; s must be big enough */ void str_cat(char s[], char t[]) {    int i, j;    i = j = 0;    while (s[i] != '\0')    /* find end of s */        i++;    while ((s[i++] = t[j++]) != '\0') /* copy t */        ;...

  • //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; cl...

    //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; class googlePlayApp { private: string name; double rating; int numInstalls; int numReviews; double price;    public: googlePlayApp(string, double, int, int, double); ~ googlePlayApp(); googlePlayApp();    string getName(); double getRating(); int getNumInstalls(); int getNumReviews(); string getPrice();    void setName(string); void setRating(double); void setNumInstalls(int); void setNumReviews(int); void setPrice(double); }; googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr)...

  • PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and...

    PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...

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
ADVERTISEMENT