Skip to content

Philosophers is a concurrency project at 42 School that simulates the classic Dining Philosophers Problem. It teaches how to manage threads, avoid race conditions, and prevent deadlocks using mutexes and proper synchronization in C.

Notifications You must be signed in to change notification settings

ayeshamk23/Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Philosophers – Concurrency and Synchronization

β€œThe art of thinking, eating, and avoiding deadlocks.”


πŸ“š Project Overview

Philosophers is a concurrency project from 42 School, completed on 31 July 2024.
It implements a simulation of the classic Dining Philosophers Problem, where multiple threads (philosophers) must alternate between thinking, eating, and sleeping while competing for shared resources (forks) without causing deadlocks or race conditions.


🎯 Project Objectives

  • Understand and apply thread management in C
  • Use mutexes to protect shared resources
  • Prevent deadlocks and starvation
  • Implement timing and logging for precise simulation

βš™οΈ Key Concepts

  • 🧡 Multithreading with pthread
  • πŸ”’ Mutexes for synchronization
  • πŸŒ€ Deadlock and starvation prevention
  • ⏱️ Timing accuracy with usleep / gettimeofday
  • πŸ“‹ Logging thread-safe actions

πŸ› οΈ How It Works

  • Each philosopher is a thread
  • Forks are represented using mutexes
  • Philosophers must take two forks to eat
  • The program must detect and handle:
    • If a philosopher dies (time to die exceeded)
    • When all have eaten enough times (optional)

πŸ’‘ Concepts Learned

  • Safe multithreaded programming
  • Real-time logic simulation
  • Shared resource management
  • Clean code structuring in low-level C

βœ… Evaluation Result

Here’s a screenshot of the successful evaluation (score: 100%) from the 42 intranet. Screen Shot 2025-05-11 at 6 42 10 PM

About

Philosophers is a concurrency project at 42 School that simulates the classic Dining Philosophers Problem. It teaches how to manage threads, avoid race conditions, and prevent deadlocks using mutexes and proper synchronization in C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published