fix print mutex is now destroyed at the end
This commit is contained in:
		
							
								
								
									
										2
									
								
								data.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								data.c
									
									
									
									
									
								
							@ -30,6 +30,7 @@ bool	data_init(t_data *data)
 | 
			
		||||
	}
 | 
			
		||||
	pthread_mutex_init(&data->forks_mutex, NULL);
 | 
			
		||||
	pthread_mutex_init(&data->stop_mutex, NULL);
 | 
			
		||||
	pthread_mutex_init(&data->print_mutex, NULL);
 | 
			
		||||
	data->stop = 0;
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
@ -53,6 +54,7 @@ void	data_destroyer(t_data *data)
 | 
			
		||||
	}
 | 
			
		||||
	pthread_mutex_destroy(&data->forks_mutex);
 | 
			
		||||
	pthread_mutex_destroy(&data->stop_mutex);
 | 
			
		||||
	pthread_mutex_destroy(&data->print_mutex);
 | 
			
		||||
	free(data->threads);
 | 
			
		||||
	free(data->forks);
 | 
			
		||||
	philos_destroyer(data);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								print.c
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								print.c
									
									
									
									
									
								
							@ -7,7 +7,6 @@
 | 
			
		||||
 | 
			
		||||
static void	print(t_data *data, size_t id, char *str)
 | 
			
		||||
{
 | 
			
		||||
	static pthread_mutex_t	print_mutex = PTHREAD_MUTEX_INITIALIZER;
 | 
			
		||||
	size_t					time;
 | 
			
		||||
 | 
			
		||||
	pthread_mutex_lock(&data->stop_mutex);
 | 
			
		||||
@ -18,9 +17,9 @@ static void	print(t_data *data, size_t id, char *str)
 | 
			
		||||
	}
 | 
			
		||||
	pthread_mutex_unlock(&data->stop_mutex);
 | 
			
		||||
	time = get_time();
 | 
			
		||||
	pthread_mutex_lock(&print_mutex);
 | 
			
		||||
	pthread_mutex_lock(&data->print_mutex);
 | 
			
		||||
	printf("%07zu %03zu %s\n", time, id + 1, str);
 | 
			
		||||
	pthread_mutex_unlock(&print_mutex);
 | 
			
		||||
	pthread_mutex_unlock(&data->print_mutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void	print_take_a_fork(t_philo *philo)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user