/Philosophers

A Classic Concurrency Problem illustrating the actions of Multithreads and Processes

Primary LanguageC

Philosophers

##The Dining Philosophers problem is a classic concurrency problem that illustrates the challenges of coordinating the actions of multiple threads or processes that share a common resource.

image

##Learning Outcomes:

  1. Threads and Processes
  2. Difference between Mutex and Semaphores
  3. Building Multithreaded applications and designing distributed systems
  4. Avoiding Deadlocks(So all don't eat at the same time)

-->> a process or thread enters a waiting state because a requested system resource is held by another waiting process, which in turn is waiting for another resource held by another waiting process

**Mutual Exclusions **Hold and Wait **No Preemptions **Circular Wait

Deadlock_at_a_four-way-stop

  1. Race Conditions and Data Race

image

Live Coding Demonstration Example:

image

Output : Its different everytime. This is not thread safe . Two threads are racing or who gets first.

image

----------- Data Race ---------------

image

Detailed explanation: https://ckk.ai/datarace

  1. Helgrind (Tool to check datarace)

  2. Avoiding Resource starvation.

Sources:

1.https://ckk.ai/miro

2.https://en.wikipedia.org/wiki/Dining_philosophers_problem 3.