Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0bvim/philosophers
In this project, you will learn the basics of threading a process. You will see how to create threads and you will discover mutexes.
https://github.com/0bvim/philosophers
algorithms clanguage gdb helgrind makefile mutex mutex-lock threads valgrind
Last synced: 1 day ago
JSON representation
In this project, you will learn the basics of threading a process. You will see how to create threads and you will discover mutexes.
- Host: GitHub
- URL: https://github.com/0bvim/philosophers
- Owner: 0bvim
- License: mit
- Created: 2024-02-21T23:39:28.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-04T02:46:19.000Z (5 months ago)
- Last Synced: 2024-11-10T02:45:44.924Z (about 1 month ago)
- Topics: algorithms, clanguage, gdb, helgrind, makefile, mutex, mutex-lock, threads, valgrind
- Language: C
- Homepage:
- Size: 399 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dining Philosophers Problem
This repository contains an implementation of the Dining Philosophers Problem in C, using pthreads (POSIX threads) for concurrency management.
## Table of Contents
- [Introduction](#introduction)
- [Problem Description](#problem-description)
- [Implementation Details](#implementation-details)
- [How to Use](#how-to-use)
- [License](./LICENSE)---
## Introduction
The Dining Philosophers Problem is a classic synchronization problem in computer science, designed to illustrate the challenges of concurrent programming. In this scenario, a number of philosophers sit around a dining table, each with a plate of spaghetti and a fork between each pair of adjacent philosophers. The philosophers spend their time either eating or thinking. To eat, a philosopher must acquire two forks—one from their left and one from their right. The challenge lies in preventing deadlocks and resource contention, ensuring that each philosopher can eat without causing conflicts with their neighbors.
This implementation provides a solution to the Dining Philosophers Problem using C and pthreads. It aims to demonstrate a practical approach to concurrency management in a multithreaded environment.
## Problem Description
The Dining Philosophers Problem can be summarized as follows:
- There are N philosophers sitting around a circular dining table.
- Each philosopher alternates between thinking and eating.
- To eat, a philosopher must pick up two forks—one from their left and one from their right.
- The challenge is to devise a strategy that allows each philosopher to eat without leading to deadlocks or resource contention.## Implementation Details
- The solution is implemented in C programming language.
- POSIX threads (pthreads) are used for managing concurrency.
- A mutex lock is employed to ensure exclusive access to shared resources (forks).
- Each philosopher is represented by a separate thread.
- The program ensures that no two adjacent philosophers can simultaneously hold the same fork.## How to Use
To run the program, follow these steps:
1. Clone this repository to your local machine.
2. Navigate to the directory containing the source code.
3. Compile the program using `make` and then `./philo (optional)`