pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/moocf/dining-philosophers-problem.java

"anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-8522af645b000615.css" /> GitHub - moocf/dining-philosophers-problem.java: The dining philosophers problem is an example problem often used in concurrent algorithm design. · GitHub
Skip to content

moocf/dining-philosophers-problem.java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

There are 5 philosophers sitting around a table. Each philosopher thinks, or when hungry eats. Each philosopher has a bowl of noodles, but there are only 5 forks between each philosopher. However, in order to eat, a philosopher needs both forks. A deadlock occurs when all philosophers pick up one fork, but are waiting for the other fork to be put down.

One idea to solve the dependency cycle is to alter the order in which the last philosopher picks up forks.

Course: Concurrent Data Structures, Monsoon 2020
Taught by: Prof. Govindarajulu Regeti

philosoper(i):
1. Think (sleep 100ms)
2. Pick left fork (i) (or wait)
3. Pick right fork (i+1) (or wait)
4. Eat (sleep 100ms)
5. Put back right fork
6. Put back left fork
...
EXCEPT the last philospher, who instead
picks up his right fork first; this is
what helps us to avoid deadlock.
## OUTPUT
5 philosophers get to work ...
0: thinking
1: thinking
2: thinking
4: thinking
3: thinking
0: eating
2: eating
0: thinking
4: eating
2: thinking
1: eating
4: thinking
3: eating
0: eating
1: thinking
3: thinking
2: eating
0: thinking
4: eating
...

See Main.java for code, and repl.it for output.

references

About

The dining philosophers problem is an example problem often used in concurrent algorithm design.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy