- ポインタを渡すときは、64ビットコピーされるので、あまりよくないかも
- check input
- argc is 5 or 6
- isnum
- num_of_philo is between 2 and 200
- time_to_die is greater than 1
- time_to_eat is greater than 1
- time_to_sleep is greater than 1
- if argc is 5, num_of_must_eat is LONG_MAX
- if argc is 6, num_of_must_eat is greater than 1
- init_var
- input input_args
- input time
- create_threads
- if num_of_must_eat != 0 (argc == 6) create observer
- create philo threads
-
- destroy mutex
typedef struct s_philo
{
struct s_arg *arg;
pthread_mutex_t *fork_left_mtx;
pthread_mutex_t *fork_right_mtx;
int id;
long last_eat_time;
pthread_mutex_t last_eat_time_m;
int num_of_eaten;
pthread_mutex_t num_of_eaten_m;
pthread_t thread;
} t_philo;
typedef struct s_arg
{
long num_of_philo;
long time_to_die;
long time_to_eat;
long time_to_sleep;
long num_of_must_eat;
bool dead;
pthread_mutex_t dead_m;
bool finish;
pthread_mutex_t finish_m;
pthread_mutex_t fork_m[MAX_PHILO];
t_philo philo[MAX_PHILO];
long start_time;
pthread_mutex_t write_mutex;
} t_arg;
- On computer at 42
_STRUCT_TIMEVAL
{
__darwin_time_t tv_sec; /* seconds */
__darwin_suseconds_t tv_usec; /* and microseconds */
};
typedef long __darwin_time_t; /* time() */
typedef __int32_t __darwin_suseconds_t; /* [???] microseconds */
typedef int __int32_t;