| rendu | ||
| subjects | ||
| testers | ||
| .gitignore | ||
| LICENSE | ||
| QUICK_START.sh | ||
| README.md | ||
| setup_testers.sh | ||
Preparatory Exercises — Philosophers Project
Welcome to the repository of practical exercises designed to build, step by step, all the concepts necessary to master the 42 Philosophers project. Here you will find progressive challenges about threads, mutexes, deadlocks, synchronization, semaphores, timing, and much more in C.
Objective
The purpose of this repository is to guide students through real concurrent programming learning, starting from the absolute basics up to the implementation of complete and robust systems capable of solving the classic Dining Philosophers problem, including the rules and challenges of the bonus part.
Exercise Structure
Each exercise follows a clear and standardized structure, including:
- Assignment name
- Expected files
- Allowed functions
- Problem description
- Hint/Suggestion for resolution
Exercise List
| No | Name | Key Content |
|---|---|---|
| 1 | thread_basics | Threads, pthread_create, pthread_join |
| 2 | mutex_basics | Mutexes, race conditions |
| 3 | precise_timing | gettimeofday, usleep, timing |
| 4 | state_monitor | Monitoring, enums, monitor patterns |
| 5 | producer_consumer | Synchronization, coordination problems |
| 6 | deadlock_demo | Deadlock, deadlock prevention |
| 7 | limited_resources | Manual semaphore, limited access |
| 8 | simple_philosophers | Simplified philosophers problem |
| 9 | death_monitor | Life monitoring, watchdog threads |
| 10 | philosophers_args | Full implementation, arguments |
| 11 | race_detector | Data races, lock optimization |
| 12 | philosophers_bonus | Processes, POSIX semaphores, bonus part |
How to Use
- Each exercise is independent. It is recommended to follow them in order to ensure progressive learning.
- Compile each exercise:
gcc -Wall -Wextra -Werror -pthread <filename>.c -o <program> - Run each binary following the instructions and examples in the exercise header.
Technical Requirements
- C Compiler (e.g., gcc)
- POSIX environment (Linux or Mac OS X recommended)
- Standard pthreads libraries
Recommendations
- Don't use external functions beyond those allowed.
- Carefully read the hints provided for each exercise.
- Analyze race condition and deadlock errors using tools like
valgrind --tool=helgrind. - Consult The Little Book of Semaphores to solidify concepts.
Credits and References
- Inspired by the open-source book The Little Book of Semaphores by Allen B. Downey.
- Structure and evaluation based on the 42 project format.
- Classic Dining Philosophers problem by Edsger W. Dijkstra.