Question

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 () eat O return (i + 4) % 5; put.forks() int right(int i) ( // Philosopher to the right of i return (i + 1) % 5; void take.forks (int i) [ P(utex) state[i]-HUNGRY test (i): void test (int ) [ (state [i] if && HUNGRY state [left (i)] !-EATING && state[right()EATING) I := V(mutex) state []-EATING: void put forks (int i) ( P(nutex) state[i]THINKING; test (left (i)) test (right() V(utex)

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
What are the three requirements for a solution to the critical-section problem? Consider the following solution...
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
  • 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)...

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

  • Consider the Dining-Philosophers problem (Chapter 5.7.3), in which a set of philosophers sit around a table...

    Consider the Dining-Philosophers problem (Chapter 5.7.3), in which a set of philosophers sit around a table with one chopstick between each of them. Let the philosophers be numbered from 0 to n−1 and be represented by separate threads. Each philosopher executes Dine(i), where “i” is the philosopher’s number. Assume that there is an array of semaphores, Chop[i] that represents the chopstick to the left of philosopher i. These semaphores are initialized to 1. void Dine( int i ) { Chop[...

  • Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for...

    Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for push_back() function as below: void push_back(string str) { // increase vector size by one // initialize the new element with str } In addition, the standard library vector doesn't provide push_front(). Implement push_front() for your vector. Test your code with the main function below. int main() {    vector v1(3);    cout<<"v1: ";    v1.print(); // this should display -, -, -    for...

  • Do the following project: Following is the file to be programmed in Linux kernel. Run this...

    Do the following project: Following is the file to be programmed in Linux kernel. Run this program. Include the screenshot of the results. Multi threaded Sorting Application Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sub list using a sorting algorithm of your choice. The two sub lists are then merged by a third thread—a...

  • Code to be written in C++: Initially, you will be given symbols printed in a preorder...

    Code to be written in C++: Initially, you will be given symbols printed in a preorder traversal of a boolean expression tree. The internal nodes of the tree will contain one of the following operators: & (and), | (or), ^ (exclusive-or), or ! (not). The nodes containing the first three operators will have two children, while the nodes containing the ! operator will contain only a left child. The leaves of the tree will contain an operand - either f...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A*...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class. For more information, please read the wiki page of 15-puzzle problem at https://en.wikipedia.org/wiki/15_puzzle, and the wiki page of...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* s...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. Please include pictures that the code runs and shows the different states as it reaches goal state please. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class....

  • 1. Your project will include the following three files: A header file: dynamicArray.h that includes a...

    1. Your project will include the following three files: A header file: dynamicArray.h that includes a list of function prototypes as enumerated in the next section. An implementation file: dynamicArray.cpp that implements the functions declared in the header file. A test driver file: dynamicArray-main.cpp that includes the main() function so that you can test all the functions you've implemented above. 2. The header file dynamicArray.h will include the following list of functions: constructing a dynamic array of the specified size...

  • Q1) Write a method called inToTree of ExpressionTree class which takes a string of infix expression...

    Q1) Write a method called inToTree of ExpressionTree class which takes a string of infix expression (fully parenthesized), resets the root of the expression tree to such tree which constructed from the expression. The root set to null of the expression contains characters other than value, operator, and parenthesis or if it’s not an in-fix full parenthesized expression. You may assume each value is single digit only . public void inToTree(String expression){ You may use a JCF Deque class as...

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