Skip to content

msabr/PHILOSOPHERS_1337

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PHILOSOPHERS - 42 Network

Implementation of the Dining Philosophers Problem, a classic concurrency challenge, using threads (mandatory) and optionally processes/semaphores (bonus).


πŸ“– The Dining Philosophers Problem

The Dining Philosophers Problem is a classic concurrency challenge first formulated by Edsger W. Dijkstra in 1965. It models synchronization, resource sharing, and deadlock avoidance in concurrent systems.


πŸͺ‘ Problem Setup

  • A group of philosophers sit around a round table.
  • There are as many forks as philosophers, one between each pair.
  • Each philosopher can:
    • Eat, sleep, or think
    • To eat, a philosopher must pick up two forks (the one to their right and the one to their left).
  • Forks are shared resources and can only be held by one philosopher at a time.
  • Philosophers cannot eat unless they have both forks.
  • Philosophers never do more than one action at a time.

πŸ”„ The Challenge

Naive implementations lead to issues such as:

  • πŸ›‘ Deadlock: All philosophers pick up one fork and wait indefinitely for the other.
  • 🧍 Starvation: Some philosophers may never get to eat.
  • πŸ’₯ Race Conditions: Without proper synchronization, concurrent access corrupts shared data.

❓ Problem Statement

How can multiple concurrent threads safely share resources (forks) without deadlocks, starvation, or data races β€” using only mutexes and thread primitives?

The project simulates N philosophers sitting around a table. Each must:

  • Take two forks (mutexes)
  • Eat for a defined duration
  • Sleep
  • Think
  • Repeat the cycle indefinitely

A monitor thread ensures no philosopher dies from starvation (exceeding time_to_die without eating).


🎯 Objective

Simulate a group of philosophers sitting around a table. Each must:

  • πŸ₯’ Take forks
  • 🍝 Eat
  • 😴 Sleep
  • πŸ’­ Think
    Without creating deadlocks or data races.

About

The classic dining philosophers problem 🍽️ simulates concurrent philosophers competing for forks, illustrating synchronization techniques to prevent deadlocks, starvation, and race conditions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors