Question
Write a semaphore based solution to Dining Philosopher problem and explain all the assumptions and the algorithm.
Answer :
Word Count : 357
______ ______ ________ __________ _________ _______ _____ _________ ____ ________.
______ ______ _________ __________ ______ _____.
_________ _________ __________ ______ _______ _______.
________ _______ __________ __________ ________ _________ _______ __________.
_______ ______ _______ ____ _____ _______ ______ ___ __________ _____ __________ _______.
____ ________ _________ ____ _________ ____ ___ ____ _____ ______.
_______ _________ _________ _____ ___ __________ ____ __________ __________ ___.
_______ ____ _____ _________ _____ ____ ______ __________.
_______ _________ _____ __________ ________ __________ _______ ___ ________.
__________ __________ ________ ________ _______ ___ _______ _______ __________ _______.
_________ ____ _____ ____ ____ _________ ________ _________ ____ ______ _______ _______.
_______ ___ __________ ______ _________ _______ ____ _________ ___.
_____ _______ _____ ________ _____.
__________ ______ ___ __________ _____.
_______ ___ ___ _______ ______ _______ _________ ___ _______ _____ _______ _______.
__________ ____ _____ ___ ____ _____ _______ _____.
______ _________ _____ _______ _______ ________ _______ ___ __________ _________ _____.
___ ___ _______ ______ ____ __________ _____ ______ ___ ____ _________ _________.
_______ ________ __________ ________ _____ _________.
________ _______ __________ _______ __________ ___ ____ ____ __________ __________ _______ ____.
__________ ___ ________ ________ _______ _______ ____ ___ __________ _____.
__________ ______ _________ ________ ______ _______.
__________ _____ __________ ____ __________ ___ ___ _________.
______ _____ ___ _____ ________ ____ _______.
____ _____ ___ ______ _____ ___ _____ _____ ___ ______ ___.
_________ _________ ______ ________ ______.
___ ___ ________ _____ __________ _____ __________ __________.
______ _______ _________ _______ _________ _________.
___ _____ _______ __________ _____.
__________ ____ ________ ______ ______.
___ __________ ______ _______ _________ __________ ________.
_________ ___ ________ ________ __________ ___ _______ _______.
_____ _________ ____ _________ __________ _______.
______ _______ _________ _______ _______.
Skip in 10
Solution written in Java
import java.util.concurrent.Semaphore;
import java.util.Random;
import java.util.Vector;
public class Philosopher extends Thread
{
private static final Random rand = new Random();
private static int event=0;
private static String binary="";
private int id;
private Semaphore sem;
private static Vector<Object[]> vector = new Vector<Object[]>();
public Philosopher(int i, Semaphore s)
{
id = i;
sem = s;
binary = binary + "0";
}
private void busy()
{
try
{
sleep(rand.nextInt(1000));
} catch (InterruptedException e){}
}
______ ______ _________ __________ ______ _____.
_________ _________ __________ ______ _______ _______.
________ _______ __________ __________ ________ _________ _______ __________.
_______ ______ _______ ____ _____ _______ ______ ___ __________ _____ __________ _______.
____ ________ _________ ____ _________ ____ ___ ____ _____ ______.
_______ _________ _________ _____ ___ __________ ____ __________ __________ ___.
_______ ____ _____ _________ _____ ____ ______ __________.
_______ _________ _____ __________ ________ __________ _______ ___ ________.
__________ __________ ________ ________ _______ ___ _______ _______ __________ _______.
_________ ____ _____ ____ ____ _________ ________ _________ ____ ______ _______ _______.
_______ ___ __________ ______ _________ _______ ____ _________ ___.
_____ _______ _____ ________ _____.
__________ ______ ___ __________ _____.
_______ ___ ___ _______ ______ _______ _________ ___ _______ _____ _______ _______.
__________ ____ _____ ___ ____ _____ _______ _____.
______ _________ _____ _______ _______ ________ _______ ___ __________ _________ _____.
___ ___ _______ ______ ____ __________ _____ ______ ___ ____ _________ _________.
_______ ________ __________ ________ _____ _________.
________ _______ __________ _______ __________ ___ ____ ____ __________ __________ _______ ____.
__________ ___ ________ ________ _______ _______ ____ ___ __________ _____.
__________ ______ _________ ________ ______ _______.
__________ _____ __________ ____ __________ ___ ___ _________.
______ _____ ___ _____ ________ ____ _______.
____ _____ ___ ______ _____ ___ _____ _____ ___ ______ ___.
_________ _________ ______ ________ ______.
___ ___ ________ _____ __________ _____ __________ __________.
______ _______ _________ _______ _________ _________.
___ _____ _______ __________ _____.
__________ ____ ________ ______ ______.
___ __________ ______ _______ _________ __________ ________.
_________ ___ ________ ________ __________ ___ _______ _______.
_____ _________ ____ _________ __________ _______.
______ _______ _________ _______ _______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.