Example #1
0
int			main()
{
  t_chopstick		chopstick[NB_PHILO];
  t_philo		philo[NB_PHILO];
  pthread_t		tab_thread[NB_PHILO];
  int			i;

  i = -1;
  while (++i < NB_PHILO)
    chopstick[i] = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
  i = -1;
  while (++i < NB_PHILO)
    init_philo(&philo[i], &chopstick[i],
	       (i == 0 ? &chopstick[NB_PHILO - 1] : &chopstick[i - 1]), i);
  i = -1;
  while (++i < NB_PHILO)
    if (pthread_create(&tab_thread[i], NULL, &start, &philo[i]) != 0)
      {
	perror(NULL);
	return (FAILURE);
      }
  i = -1;
  while (++i < NB_PHILO)
    pthread_join(tab_thread[i], NULL);
  return (SUCCESS);
}
Example #2
0
int	main()
{
  t_philo	*philo;

  if ((philo = init_philo()) == NULL)
    return (-1);
  init_mut();
  launch_philo(philo);
  return (0);
}
Example #3
0
int		main()
{
  t_philo	philosophes[NB_PHILO];
  int		i;

  i = 0;
  init_mutex_stick();
  init_philo(philosophes);
  init_thread(philosophes);
  while (i < NB_PHILO)
    {
      if (pthread_join(philosophes[i].th_philo, NULL) != 0)
	return (EXIT_FAILURE);
      ++i;
    }
  return (0);
}
Example #4
0
int	main(void)
{
	pthread_t	main_thread;

	if (NB_PHILO <= 3)
		write(1, "NB_PHILO must be greater than 3\n", 32);
	else
	{
		init_sticks();
		if (init_philo() == 1)
		{
			pthread_create(&main_thread, NULL, main_rootine, NULL);
			pthread_join(main_thread, NULL);
		}
	}
	return (0);
}