From a09654e80f59db4caa67387817023279fbda42a1 Mon Sep 17 00:00:00 2001 From: junyjeon Date: Thu, 24 Oct 2024 04:17:19 +0900 Subject: [PATCH] docs: Update README.md --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 153a033..6ae883f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

🍝 Philosophers

42Seoul의 λ©€ν‹°μŠ€λ ˆλ”© ν”„λ‘œμ νŠΈ: μ‹μ‚¬ν•˜λŠ” μ² ν•™μžλ“€μ˜ 문제

- philosophers code review + philosophers code review [![42 Score](https://img.shields.io/badge/Score-125%2F100-success?style=for-the-badge&logo=42)](https://github.com/your-username/philosophers) [![Norminette](https://img.shields.io/badge/Norminette-passing-brightgreen?style=for-the-badge)](https://github.com/42School/norminette) @@ -197,6 +197,69 @@ void *monitor(void *arg) } ``` +## 🌟 λ³΄λ„ˆμŠ€ 파트 + +### 1. μ„Έλ§ˆν¬μ–΄ 버전 +```c +// μ„Έλ§ˆν¬μ–΄ μ΄ˆκΈ°ν™” +sem_t *forks; +forks = sem_open("/forks", O_CREAT, 0644, num_philos); + +// 포크 νšλ“ +void take_forks_sem(t_philo *philo) +{ + sem_wait(philo->data->forks); + print_state(philo, "has taken a fork"); + sem_wait(philo->data->forks); + print_state(philo, "has taken a fork"); +} + +// 포크 λ°˜ν™˜ +void release_forks_sem(t_philo *philo) +{ + sem_post(philo->data->forks); + sem_post(philo->data->forks); +} +``` + +## πŸ”§ 디버깅 κ°€μ΄λ“œ + +### 1. λ°λ“œλ½ 디버깅 +```c +// λ°λ“œλ½ 감지λ₯Ό μœ„ν•œ λ‘œκΉ… +void log_fork_status(t_philo *philo) +{ + printf("Philo %d trying to take forks at %llu ms\n", + philo->id, get_time() - philo->data->start_time); +} +``` + +### 2. μ‹œκ°ν™” 도ꡬ +```bash +# μ‹€ν–‰ μƒνƒœ μ‹œκ°ν™” (별도 슀크립트 ν•„μš”) +./visualizer.py ./philo 5 800 200 200 +``` + +### 3. 일반적인 디버깅 팁 +- gdb μ‚¬μš©ν•˜μ—¬ μŠ€λ ˆλ“œ 좔적 +- valgrind둜 λ©”λͺ¨λ¦¬ λˆ„μˆ˜ 확인 +- helgrind둜 데이터 레이슀 확인 + +### 4. μ² ν•™μž ν…Œμ΄λΈ” λ°°μΉ˜λ„ +``` + 🍽️ Fork + ↑ + Phil1 ←πŸͺ‘β†’ Phil2 + β†— β†˜ +🍽️ 🍽️ +↑ ↓ +Phil5 Phil3 + β†– ↙ + Phil4 + ↓ + 🍽️ +``` + ## πŸ”„ 동기화 처리 ### 1. 포크 관리