https://github.com/pamaldi/many-virtual-dining-philosophers
Classical dining philosophers concurrency problem with java virtual threads
https://github.com/pamaldi/many-virtual-dining-philosophers
Last synced: 26 days ago
JSON representation
Classical dining philosophers concurrency problem with java virtual threads
- Host: GitHub
- URL: https://github.com/pamaldi/many-virtual-dining-philosophers
- Owner: pamaldi
- License: mit
- Created: 2023-04-17T12:09:23.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T20:03:54.000Z (over 3 years ago)
- Last Synced: 2025-08-04T17:57:54.123Z (12 months ago)
- Language: Java
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Many virtual dining philosophers.
Many virtual dining philosophers is a Java implementation of a classic concurrency problem:
[Dining Philosophers](https://en.wikipedia.org/wiki/Dining_philosophers_problem)
using [communicating sequential processes (CSP)](https://en.wikipedia.org/wiki/Communicating_sequential_processes).
It's an extension of the original one problem, from five to many philosophers.
The purpose of this extension is to compare a Virtual Threads based implementation with a Native Threads based one.
## CSP solution
The CSP solution is based on a number of channels.
For each philosopher there are two channels, one for the left fork and one for the right fork.
To avoid deadlock there is an any to one channel for every philosopher, which is used to signal that the philosopher is done eating.
The any to one channel il an n-1 blocking queue, where n is the number of philosophers.
## Virtual Threads implementation
Every philosopher is a virtual thread, which is started by the main thread, which is also the coordinator.
## Native Threads implementation
Every philosopher is a native thread, which is started by the main thread, which is also the coordinator.
## Build
[OpenJDK 20](https://www.oracle.com/java/technologies/javase/jdk20-archive-downloads.html)
is required.
## Command Line Arguments
1. PhilosopherType philosopherType: GREEK for native Threads, GERMAN for virtual Threads
2. Integer numberOfPhilosophers
3. Long thinkingTime (in milliseconds)
4. Long eatingTime (in milliseconds)
5. Integer cycles: number of eating cycles for each philosopher
## Benchmark
Some benchmark results
