Skip to content

Commit

Permalink
philo
Browse files Browse the repository at this point in the history
  • Loading branch information
m3zh committed Nov 10, 2021
1 parent 87675b5 commit d59d010
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- [ ] If you get an infinite loop somewhere before the end of your code, check the way you have locked and unlocked your mutex

- [ ] If your code runs smoothly till the end (i.e. the death of a philosophers), but it gets stuck without exiting, the problem lies in `pthread_join`. `pthread_join` blocks if a thread has not terminated until it actually is, and does not return; use `pthread_detach` instead, it returns immediately without terminating the thread though.
- [ ] If your code runs smoothly till the end (i.e. the death of a philosophers), but it gets stuck without exiting, it means there is a mutex still locked somewhere.
Solution 1: try `pthread_detach` instead of `pthread_join`. `pthread_join` blocks if a thread has not terminated until it actually is; `pthread_detach` returns immediately without terminating the thread (you might have leaks though, because the thread is detached but keep running in the background (if you do a while loop after detaching the thread, you'll see it running in the shell, try it out!).
Solution 2: another way to go about it and keep using `pthread_join` is to check that all mutex have been correctly unlocked


4 changes: 2 additions & 2 deletions philo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# By: mlazzare <mlazzare@student.s19.be> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/09/15 12:21:19 by mdesalle #+# #+# #
# Updated: 2021/11/02 14:22:52 by mlazzare ### ########.fr #
# Updated: 2021/11/10 12:26:55 by mlazzare ### ########.fr #
# #
# **************************************************************************** #

NAME = philo

CC = gcc -g3
CC = gcc
CFLAGS = -Wall -Wextra -Werror
#CFLAGS += -fsanitize=address

Expand Down
4 changes: 2 additions & 2 deletions philo_bonus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# By: mlazzare <mlazzare@student.s19.be> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/09/15 12:21:19 by mdesalle #+# #+# #
# Updated: 2021/11/07 16:15:45 by mlazzare ### ########.fr #
# Updated: 2021/11/10 12:26:40 by mlazzare ### ########.fr #
# #
# **************************************************************************** #

NAME = philo

CC = gcc -g3
CC = gcc
CFLAGS = -Wall -Wextra -Werror
#CFLAGS += -fsanitize=address

Expand Down
4 changes: 2 additions & 2 deletions philo_mac/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# By: mlazzare <mlazzare@student.s19.be> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/09/15 12:21:19 by mdesalle #+# #+# #
# Updated: 2021/11/05 09:56:05 by mlazzare ### ########.fr #
# Updated: 2021/11/10 12:26:34 by mlazzare ### ########.fr #
# #
# **************************************************************************** #

NAME = philo

CC = gcc -g3
CC = gcc
CFLAGS = -Wall -Wextra -Werror
#CFLAGS += -fsanitize=thread

Expand Down

0 comments on commit d59d010

Please sign in to comment.