Correction mutex ecriture

This commit is contained in:
Xamora 2023-04-07 11:31:40 +02:00
parent 3f0ec62059
commit af6b1bacf3
25 changed files with 9 additions and 4 deletions

BIN
philo/main.o Normal file

Binary file not shown.

View file

@ -19,10 +19,10 @@ static t_same *create_struct_same(t_config *config)
same = ft_calloc(sizeof(t_same), 1); same = ft_calloc(sizeof(t_same), 1);
if (!same) if (!same)
return (NULL); return (NULL);
same->mutex = ft_calloc(sizeof(pthread_mutex_t), config->nbr_philo + 2); same->mutex = ft_calloc(sizeof(pthread_mutex_t), config->nbr_philo + 3);
if (!same->mutex) if (!same->mutex)
return (NULL); return (NULL);
init_mutex(same->mutex, config->nbr_philo + 2); init_mutex(same->mutex, config->nbr_philo + 3);
same->config = config; same->config = config;
same->death = ft_calloc(sizeof(int), 1); same->death = ft_calloc(sizeof(int), 1);
if (!same->death) if (!same->death)

BIN
philo/manage_threads.o Normal file

Binary file not shown.

BIN
philo/parsing.o Normal file

Binary file not shown.

BIN
philo/philo Executable file

Binary file not shown.

BIN
philo/threads.o Normal file

Binary file not shown.

BIN
philo/utils/ft_atoi.o Normal file

Binary file not shown.

BIN
philo/utils/ft_atoi_check.o Normal file

Binary file not shown.

BIN
philo/utils/ft_bzero.o Normal file

Binary file not shown.

BIN
philo/utils/ft_calloc.o Normal file

Binary file not shown.

BIN
philo/utils/ft_itoa.o Normal file

Binary file not shown.

View file

@ -30,7 +30,7 @@ int ft_lltos(char *str, long long n)
q *= 10; q *= 10;
while (q > 0) while (q > 0)
{ {
str[i++] = (n / q % 10) + 48; str[i++] = (v / q % 10) + 48;
q /= 10; q /= 10;
} }
str[i] = '\0'; str[i] = '\0';

BIN
philo/utils/ft_lltos.o Normal file

Binary file not shown.

BIN
philo/utils/ft_memset.o Normal file

Binary file not shown.

BIN
philo/utils/ft_putchar_fd.o Normal file

Binary file not shown.

BIN
philo/utils/ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
philo/utils/ft_putstr_fd.o Normal file

Binary file not shown.

BIN
philo/utils/ft_strcat.o Normal file

Binary file not shown.

BIN
philo/utils/ft_strcpy.o Normal file

Binary file not shown.

BIN
philo/utils/ft_strlen.o Normal file

Binary file not shown.

BIN
philo/utils/utils.a Normal file

Binary file not shown.

View file

@ -34,7 +34,7 @@ void free_all(pthread_t *threads, t_same *same, t_philo **philo)
{ {
int i; int i;
destroy_mutex(same->mutex, same->config->nbr_philo + 2); destroy_mutex(same->mutex, same->config->nbr_philo + 3);
if (threads) if (threads)
free(threads); free(threads);
if (same && same->mutex) if (same && same->mutex)

Binary file not shown.

View file

@ -27,6 +27,8 @@ void message_die(t_philo *philo, char *msg)
int i; int i;
config = philo->same->config; config = philo->same->config;
pthread_mutex_lock(&philo->same->mutex[config->nbr_philo + 2]);
i = ft_lltos(send, (get_utime() - philo->same->time) / 1000); i = ft_lltos(send, (get_utime() - philo->same->time) / 1000);
send[i++] = ' '; send[i++] = ' ';
i += ft_lltos(send + i, philo->only->id + 1); i += ft_lltos(send + i, philo->only->id + 1);
@ -34,6 +36,7 @@ void message_die(t_philo *philo, char *msg)
while (*msg) while (*msg)
send[i++] = *msg++; send[i++] = *msg++;
write(1, send, i); write(1, send, i);
pthread_mutex_unlock(&philo->same->mutex[config->nbr_philo + 2]);
} }
void message(t_philo *philo, char *msg) void message(t_philo *philo, char *msg)
@ -43,6 +46,7 @@ void message(t_philo *philo, char *msg)
int i; int i;
config = philo->same->config; config = philo->same->config;
pthread_mutex_lock(&philo->same->mutex[config->nbr_philo + 2]);
i = ft_lltos(send, (get_utime() - philo->same->time) / 1000); i = ft_lltos(send, (get_utime() - philo->same->time) / 1000);
send[i++] = ' '; send[i++] = ' ';
i += ft_lltos(send + i, philo->only->id + 1); i += ft_lltos(send + i, philo->only->id + 1);
@ -51,6 +55,7 @@ void message(t_philo *philo, char *msg)
send[i++] = *msg++; send[i++] = *msg++;
if (!finish(philo, philo->only->last_eat_time)) if (!finish(philo, philo->only->last_eat_time))
write(1, send, i); write(1, send, i);
pthread_mutex_unlock(&philo->same->mutex[config->nbr_philo + 2]);
} }
int verif_finish(t_philo *philo, t_only *only) int verif_finish(t_philo *philo, t_only *only)

BIN
philo/utils_threads.o Normal file

Binary file not shown.