Question
Explain whether this code avoids deadlock and starvation. Give detailed reasoning.
semaphore fork5-1 semaphore s ## 1 int i void philosopher(int ai) while(true) f think: wait (s); wait (forki); wait(forkfi +1 mod 5); signal(% eat ): wait(s); signal(fork]); signal(forkli +1] mod 5); signal(s):
0 0
Add a comment Improve this question Transcribed image text
Answer #1

nikally HakD Fank (1 20 Hakon Sblacked-_00. d a unte diad lack aD

THUMBS UP IF YOU ARE SATISFIED WITH THE ANSWER OTHERWISE REPLY WITH YOUR CONCERN.

Add a comment
Know the answer?
Add Answer to:
Explain whether this code avoids deadlock and starvation. Give detailed reasoning. semaphore fork5-1 semaphore s ##...
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
  • How to change this C code to java? dining_philosopher.c #define N 5 /* number of philosophers...

    How to change this C code to java? dining_philosopher.c #define N 5 /* number of philosophers */ void philosopher(int i) /* i: philosopher number, from 0 to 4 */ { while (TRUE) { think(); /* philosopher is thinking */ take_fork(i); /* take left fork */ take_fork((i+1) % N); /* take right fork; % is modulo operator */ eat(); /* yum-yum, spaghetti */ put_fork(i); /* put left fork back on the table */ put_fork((i+1) % N); /* put right fork back...

  • What are the three requirements for a solution to the critical-section problem? Consider the following solution...

    What are the three requirements for a solution to the critical-section problem? Consider the following solution to the dining-philosophers' problem. // Global variables. Shared among threads int state [5]; semaphore mutex; I/ Initially set to 1 semaphore s [5] I Initially s[i] is set to 0 for all i Initially statei]-THINKING for all i void philosopher (int i) f int left(int i) f // Philosopher to the left of i // % is the mod operator. while(TRUE) thinkO take.forks ()...

  • Using the following pseudocode write a c program that solves the dining philosophers problem. #define N...

    Using the following pseudocode write a c program that solves the dining philosophers problem. #define N 5 #define LEFT (i+N-1)%N #define RIGHT (i+1)%N #define THINKING 0 #define HUNGRY 1 #define EATING 2 typedef int semaphore; int state[N]; semaphore mutex = 1; semaphore s[N]; void philosopher(int i) { while(TRUE) { think(); take_forks(i); eat(); put_forks(i); } } void take_forks(int i) { down(&mutex); state[i] = HUNGRY; test(i); up(&mutex); down(&s[i]); } void put_forks(i) { down(&mutex); state[i] = THINKING; test(LEFT); test(RIGHT); up(&mutex); } void test(i)...

  • Computer Science - Java Explain the code step by step (in detailed order). Also explain what...

    Computer Science - Java Explain the code step by step (in detailed order). Also explain what the program required. Thanks 7 import java.io.File; 8 import java.util.Scanner; 9 import java.util.Arrays; 10 import java.io.FileNotFoundException; 12 public class insertionSort 13 14 public static void insertionSort (double array]) 15 int n -array.length; for (int j-1; j < n; j++) 17 18 19 20 21 double key - array[j]; int i-_1 while ( (i > -1) && ( array [i] > key array [i+1] -...

  • 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,...

  • Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 1...

    Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 100 #define maxint 10000 void dijkstra(int n,int v,int dist[],int prev[],int c[][NUM]) {    int i,j;    bool s[NUM];    for(i=1; i<=n; i++)    {        dist[i] = c[v][i];        s[i] = false;        if (dist[i]>maxint) prev[i] = 0;        else prev[i] = v;    }    dist[v] = 0;    s[v] = true;    for(i=1; i<n; i++)    {        int tmp = maxint;        int u = v;        for(j=1; j<=n; j++)            if(!(s[j]) && (dist[j]<tmp))            {                u = j;                tmp = dist[j];           ...

  • C++ Questions Please answer quickly! 1. Please use this info to answer next questions -> 2. Please give reasoning 4. Explain why, I think it is 4 but i also think it might be 0. You need to wri...

    C++ Questions Please answer quickly! 1. Please use this info to answer next questions -> 2. Please give reasoning 4. Explain why, I think it is 4 but i also think it might be 0. You need to write a program that uses the speed of light in a vacuum (299792458 meters per second) Realizing that this is a very large value, you run this code to see how large a value you can store as an int, a long...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • Java BlackJack Game: Help with 1-4 using the provided code below Source code for Project3.java: import...

    Java BlackJack Game: Help with 1-4 using the provided code below Source code for Project3.java: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Project3 extends JFrame implements ActionListener { private static int winxpos = 0, winypos = 0; // place window here private JButton exitButton, hitButton, stayButton, dealButton, newGameButton; private CardList theDeck = null; private JPanel northPanel; private MyPanel centerPanel; private static JFrame myFrame = null; private CardList playerHand = new CardList(0); private CardList dealerHand = new CardList(0);...

  • please explain all the steps. I need it ASAP. i will give u good ratings. Do...

    please explain all the steps. I need it ASAP. i will give u good ratings. Do in java file Queues are often used to simulate the flow of people, cars, airplanes, transactions, and so on. Write a program that models checkout lines at a supermarket, using the Queue class from the queue.java program (Listing 4.4). Several lines of customers should be displayed; you can use the display, insertſ), and remove() method. You can add a new customer by pressing a...

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