Dining Philosophers Problem:
I need explanation with the following implementation
Starvation? | Deadlock? | |
Spin lock | ||
Semaphore with queues |
Answer:
(a) if we implement dinning philosopher using locking protocol then suppose more than two philosophers are waiting for eating to get the chopstick all waiting philosopher is continuously checking the locks which cause busy waiting and as well as known as spin-lock but there is no chance of deadlock with the correct solution of dinning philosopher but there is chance of starvation because suppose if both philosophers are waiting and continuously checking the lock if philosopher 1 one get chance of getting chopstick then philosopher 2 still waits in spin-lock now again the recent philosopher willing to eat then again they will also check the lock now suppose philosopher 1 release chopstick then there might be chance that philosopher 3 will get chopstick but still philosopher2 in waiting for state such situation leads starvation but not deadlock.
b) The second solution is semaphore in queue order which will have neither deadlock nor starvation because semaphore has been introduced to get rid of a spinlock.
DEAR PLEASE DO RATE THE ANSWER IF HELPS ELSE LET ME KNOW YOUR DOUBTS IN COMMENTS (HAPPY TO HELP).
THANK YOU!!!
Dining Philosophers Problem: I need explanation with the following implementation Starvation? Deadlock? Spin lock Semaphore with queues
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[...
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)...
what is a problem with using a spin lock instead of a mutex? a. small critical sections that are executed repeatedly by the same thread, can cause problems in the CPU itself due to centrifugal force b. if the critical section is large, CPU time can be wasted when two threads try to execute the critical section at the same time c. spin locks are always better than mutexes if you don’t need condition variables d. spin locks are not...
what is a problem with using a spin lock instead of a mutex? a. small critical sections that are executed repeatedly by the same thread, can cause problems in the CPU itself due to centrifugal force b. if the critical section is large, CPU time can be wasted when two threads try to execute the critical section at the same time c. spin locks are always better than mutexes if you don’t need condition variables d. spin locks are not...
I need a help to solve this problem I want to create a code that implement bounded buffer problem by using semaphore. so use int buffer[10]; // buffer is global variable and buffersize is 10 and there is only one producer and one consumer. 1) Producer() - At every 200msec, generates random positive integer and add to the buffer. - Then print current state of buffer (numbers and in/out indices) -Also print current state of two semaphore which are full...
1. True-false or multiple choice. Provide a one-sentence explanation you will get no credit for a correct answer without a proper explanation. Suggested time to spend on these questions: 10 minutes. [4x5-20ptsl (a) True or false: Peterson's algorithm for mutual exclusion offers bounded wait. b) Thue or falher Cumsider a concumcent program comitingof several 1oad indctioms e instructions (or instructions with similar effects as store). Such a program can never have any race conditions (c) True or false: Solutions based...
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 ()...
I
need an explanation on this problem
7. The following ik규ans, used to take the sample of five radios w and what direction you would mve within the Fiw numben would be 3754 (D42개, 4419 5785 6149
I need help in the following I need a good explanation of the following since I am learning :) what it means to code in the area of digital systems?
Hi. I need help along with an explanation for this particular problem. I would appreciate it. Which of the following are related parties under § 267? Father Brother Niece Uncle Cousin Grandson Corporation and a 45% shareholder Corporation and a 55% shareholder