https://github.com/aabduvak/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/aabduvak/philosophers
42born2code 42istanbul 42school multithreading mutex semaphore
Last synced: 3 months 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/aabduvak/philosophers
- Owner: aabduvak
- License: gpl-3.0
- Created: 2022-04-11T20:21:50.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-30T12:59:23.000Z (over 2 years ago)
- Last Synced: 2025-01-08T10:12:00.993Z (5 months ago)
- Topics: 42born2code, 42istanbul, 42school, multithreading, mutex, semaphore
- Language: C
- Homepage:
- Size: 58.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🍝 Philosophers
I’ve never thought philosophy would be so deadly
![]()
About |
Links |
Functions |
Starting |
Author
## About ##
Philosophers (represented by parts of a program) sit around a table, with a big plate of spaghetti at its center. They each have a fork, but they need two forks to eat ; so they need to borrow their neighbor's fork to eat.
Of course, if they borrow a neighbor's fork, the neighbor can't use the fork. The processes / threads must communicate, to know the state of the forks (and of the other philosophers) at all times. There must also be a parent process that monitors everything.
#### Objectives
- Unix logic#### Skills
- Rigor
- Unix
- Algorithms & AI#### My grade
## Functions ##
Only the following functions are allowed to be used in this project on mandatory part:
| Function | Description | Function | Description |
|----------|-------------|----------|-------------|
| memset | fill memory with a constant byte | pthread_create | create a new thread |
| printf | format and print data | pthread_detach | detach a thread |
| malloc | allocate dynamic memory | pthread_join | join with a terminated thread |
| free | free dynamic memory | pthread_mutex_init | initialise the mutex |
| write | write to a file descriptor | pthread_mutex_destroy | destroy the mutex object |
| usleep | suspend execution for microsecond intervals | pthread_mutex_lock | lock the mutex object |
| gettimeofday | get the time and gives the number of seconds and microseconds since the Epoch | pthread_mutex_unlock | releases the mutex object |## Starting ##
```bash
# Clone this project
git clone https://github.com/aabduvak/philosophers
# Access
cd philosophers/philo/
# Compile the program
make
# To run (example)
./philo 10 80 80 80 2
# To remove objects
make clean
# To remove objects and executable
make fclean
```## Links ##
- [Dining Philosophers Problem 1](https://www.youtube.com/watch?v=NbwbQQB7xNQ)
- [Dining Philosophers Problem 2](https://www.youtube.com/watch?v=trdXKhWAGdg)
- [Notion1](https://www.notion.so/Philosophers-2b872948598e4f0cba91c66d8b5ba821) by [jfreitas](https://github.com/joycemacksuele)
- [Notion2](https://grizzly-muenster-737.notion.site/Philosophers-55c385e0a6224d629c86231821e3ce10) by [lfrasson](https://github.com/laisarena)
- [To understand time 1](https://github.com/laisarena)
- [To understand time 2](https://stackoverflow.com/questions/60932647/gettimeofday-why-use-both-seconds-and-microseconds)
- [Tester](https://github.com/GOAT095/philosophers-tester)
- [Script Maroto xD](https://github.com/GOAT095/philosophers-tester/blob/master/delay_o_meter.py)
- [pthreads Tutorial](https://randu.org/tutorials/threads/)
- [Playlist about C Threads](https://www.youtube.com/watch?v=d9s_d28yJq0&list=PLfqABt5AS4FmuQf70psXrsMLEDQXNkLq2)
- [pthreads Short Introduction](https://www.youtube.com/watch?v=d9s_d28yJq0)
- [How to pass arguments to threads](https://www.youtube.com/watch?v=HDohXvS6UIk)
- [What are detached threads?](https://www.youtube.com/watch?v=-i8Kzuwr4T4)
- [An Application of Pthreads and Mutexes](http://files.kipr.org/gcer/2009/proceedings/Myers_ApplicationPthreads.pdf)
- [Multithreading part 1](https://www.youtube.com/watch?v=GNw3RXr-VJk)
- [Multithreading part 2](https://www.youtube.com/watch?v=sDLQWivf1-I)
- [Miro](https://miro.com/app/board/o9J_l0AjIkc=/) by [lorenuar](https://github.com/lorenuars19)
- [Visualizer](https://nafuka11.github.io/philosophers-visualizer/)
- [Figurinha](https://excalidraw.com/#json=6229317793087488,Xvs-N9yiAj1uWS7JCOepZQ) by [pcunha](https://github.com/PCC19)