Go to file
2025-10-14 20:37:03 +01:00
rendu Added semaphore_basic exercice and fixed the tester. 2025-10-14 20:37:03 +01:00
subjects Added process_basics.c exercice, renamed exercices 2025-10-14 19:54:19 +01:00
testers Added semaphore_basic exercice and fixed the tester. 2025-10-14 20:37:03 +01:00
.gitignore Initial commit 2025-10-07 08:17:44 +00:00
LICENSE Added exercices in portuguese 2025-10-07 12:20:55 +01:00
QUICK_START.sh Moved subjects to ./subjects, added subject testers 2025-10-07 14:54:09 +01:00
README.md Translated subjects to English 2025-10-07 12:49:38 +01:00
setup_testers.sh Moved subjects to ./subjects, added subject testers 2025-10-07 14:54:09 +01:00

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

  1. Each exercise is independent. It is recommended to follow them in order to ensure progressive learning.
  2. Compile each exercise:
    gcc -Wall -Wextra -Werror -pthread <filename>.c -o <program>
    
  3. 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.