86 lines
1.3 KiB
C
86 lines
1.3 KiB
C
#include "../includes/philo_header.h"
|
||
|
||
void *run_trhead(t_philo *philo)
|
||
{
|
||
philo->worked = 1;
|
||
|
||
while(1)
|
||
{
|
||
if (philo->can_run_simulation)
|
||
{
|
||
printf("я могу что то делать ура я %d\n", philo->nbr_philo);
|
||
}
|
||
}
|
||
return(NULL);
|
||
}
|
||
|
||
|
||
void philo_think(t_all *all, int i)
|
||
{
|
||
time_t time;
|
||
|
||
pthread_mutex_lock(&all->data_philo->mutex[all->data_philo->philors[i].less_fork]);
|
||
pthread_mutex_lock(&all->data_philo->mutex[all->data_philo->philors[i].more_fork]);
|
||
time = ft_get_time();
|
||
time = ft_get_time();
|
||
}
|
||
|
||
int run_observer(t_all *all)
|
||
{
|
||
int i;
|
||
int died;
|
||
time_t time;
|
||
|
||
i = 0;
|
||
died = 0;
|
||
time = ft_get_time();
|
||
while(1)
|
||
{
|
||
i = 0;
|
||
while(i <= all->number_of_philosophers)
|
||
{
|
||
if (all->data_philo->philors[i].died == 0)
|
||
{
|
||
time = ft_get_time();
|
||
// printf("%ld\n", time - all->start_time);
|
||
i++;
|
||
}
|
||
else
|
||
{
|
||
died = 42;
|
||
break;
|
||
}
|
||
}
|
||
if (died == 42)
|
||
{
|
||
printf("симуляция окончена фил умер\n");
|
||
break;
|
||
}
|
||
}
|
||
return (0);
|
||
}
|
||
|
||
|
||
int runner(t_all *all, int optional)
|
||
{
|
||
if (optional)
|
||
{
|
||
prepare_resources(all);
|
||
all->start_time = ft_get_time();
|
||
run_all_phils(all);
|
||
if (check_all_run(all))
|
||
{
|
||
run_simulation(all);
|
||
}
|
||
if (!run_observer(all))
|
||
{
|
||
return(0);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return(1);
|
||
}
|
||
return(1);
|
||
}
|