An open API service indexing awesome lists of open source software.

https://github.com/cypri1-dev/42_philosophers

The 42 Philosophers project is a programming exercise to learn about concurrency and synchronization. Inspired by Dijkstra's philosopher problem, it simulates philosophers alternating between eating, thinking, and sleeping while avoiding deadlocks and starvation. It helps develop skills in managing threads, mutexes, and semaphores.
https://github.com/cypri1-dev/42_philosophers

philosophers philosophers-dinner-problem philosophers42 threads

Last synced: 4 months ago
JSON representation

The 42 Philosophers project is a programming exercise to learn about concurrency and synchronization. Inspired by Dijkstra's philosopher problem, it simulates philosophers alternating between eating, thinking, and sleeping while avoiding deadlocks and starvation. It helps develop skills in managing threads, mutexes, and semaphores.

Awesome Lists containing this project

README

          

##


## Description
The philosophers project is a classic exercise in concurrent programming. Inspired by Dijkstra's dining philosophers problem, it involves creating a simulation where philosophers alternatively eat, think, and sleep. The challenge lies in managing shared resources (forks) and ensuring no philosopher starves or causes a deadlock.

## Project Compenents Table
This is an overview of the main components located in the "sources" directory of the philosophers project.

## Usage
To use the philosophers program, compile it using the provided Makefile. Then, run the program with the required arguments:
```bash
./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]
```
## Features
The philosophers project offers the following features:
- Concurrent Simulation: Simulates multiple philosophers engaging in eating, thinking, and sleeping concurrently.
- Resource Management: Uses mutexes to manage access to shared forks, preventing deadlocks and ensuring fairness.
- Customizable Parameters: Allows the user to specify the number of philosophers, and various time parameters to tailor the simulation.
- Error Handling: Properly handles errors and provides informative messages, ensuring robustness.
## Example
To see the philosophers simulation in action with 5 philosophers, where each philosopher dies if they do not eat within 800ms, takes 200ms to eat, and sleeps for 100ms:
```bash
./philo 5 800 200 100
```
For more detailed information, please refer to the project documentation and the source code comments.