1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NARA [144]
4 years ago
13

Implement the Dining Philosophers problem (described on pages 167-170 in the textbook (chapter 2.5.1)). Create a Graphical User

Interface - showing which philosopher is eating, and which is waiting/thinking at any given time. Show the forks. Use Java programming language for this project.
Computers and Technology
1 answer:
zhuklara [117]4 years ago
3 0

Answer: Provided in the explanation section

Explanation:

class philosopher extends Thread

{

public void run()

{

diningps.count++;

philosopher(diningps.count);

}

public void philosopher(int i)

{

take_forks(i);

System.out.println(i+"philosopher Eating");

put_forks(i);

}

public void take_forks(int i)

{

while(diningps.mutex<=0)

{

System.out.println(i+"philosopher has to be wait while other philosopher in testing");

}

diningps.state[i]="HUNGRY";

test(i);

diningps.mutex=1;

while(diningps.S[i]<=0)

{

System.out.println(i+"philosopher has to be wait while his left or right side philosopher eating.");

}

}

public void put_forks(int i)

{

while(diningps.mutex<=0)

{

System.out.println(i+"philosopher has to be wait while other philosopher in testing");

}

diningps.state[i]="THINK";

test((i+4)%5);

test((i+1)%5);

diningps.mutex=1;

}

public void test(int i)

{

if(diningps.state[i]=="HUNGRY" && diningps.state[(i+4)%5]!="EAT" && diningps.state[(i+1)%5]!="EAT")

{

diningps.state[i]="EAT";

diningps.S[i]=1;

}

}

}

class diningps

{

static int mutex=1;

static int S[]={0,0,0,0,0};

static String state[]={"THINK","THINK","THINK","THINK","THINK"};

static int count=-1;

public static void main(String ar[])

{

philosopher ob=new philosopher();

philosopher ob1=new philosopher();

philosopher ob2=new philosopher();

philosopher ob3=new philosopher();

philosopher ob4=new philosopher();

ob.start();

ob1.start();

ob2.start();

ob3.start();

ob4.start();

}

}

cheers i hope this helped !!

You might be interested in
How is blockchain different from traditional database models?
Natasha2012 [34]

Answer:

The primary difference between a blockchain and a database is centralization. While all records secured on a database are centralized, each participant on a blockchain has a secured copy of all records and all changes so each user can view the provenance of the data.

5 0
2 years ago
Explain how it makes you feel that you must share the road with others
Tpy6a [65]
I feel like it is good to share the road.

8 0
3 years ago
Select the best answer that completes the following sentences. Wireless technology changed the workday to
Minchanka [31]

Answer: around the clock availability

Explanation: i got 100

6 0
3 years ago
Read 2 more answers
When entering a formula or function into a cell, most spreadsheet programs require that you begin with some type of symbol, usua
olga_2 [115]
This is a false statement, if that's the question.
4 0
3 years ago
Jenny is working on a laptop computer and notices that the computer is not running very fast. She looks and realizes that the la
nirvana33 [79]

Answer:

SO-DIMM DDR3

Explanation:

Based on the information provided within the question it can be said that the module that Jenny needs to order is known as SO-DIMM DDR3. This is the type of module that would work on her laptop computer. DDR3 is the most common generation of these RAM modules and SO-DIMM are rams that support 72, 100, 144, or 204 pins and is alot smaller than regular DIMM modules, coming in at about 3 inches.

8 0
3 years ago
Other questions:
  • Exp19_Excel_AppCapstone_Intro_Collection
    10·1 answer
  • An independent frame that holds a program, document, or folder contents in windows 7 is called a ____.
    11·1 answer
  • The most widely used presentation software program is Microsoft PowerPoint. You can produce a professional and memorable present
    15·1 answer
  • Allow chrome to access the network in your firewall or antivirus settings. if it is already listed as a program allowed to acces
    15·1 answer
  • Jeremy, a newly appointed assistant Director, is excited about his job. the director of the movie has assigned him the responsib
    6·1 answer
  • Which software documentation guideline did the IEEE establish?
    10·1 answer
  • Write an algorithm and flowchart to display H.C.F and L.C.M of given to numbers.​
    9·1 answer
  • Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .dat
    10·1 answer
  • WHO WANT P O I N T S.................................................
    9·1 answer
  • What is the size of the rc.conf file in bytes
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!