/* ** Program: Dining Philosophors Problem ** Author : Atsuki Shimoji ** Note : This is a single running program. */ #include "dpp.h" __code putdown_lfork(PhilsPtr self) { printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id); self->left_fork->owner = NULL; goto thinking(self); } __code putdown_rfork(PhilsPtr self) { printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id); self->right_fork->owner = NULL; goto putdown_lfork(self); } __code eating(PhilsPtr self) { printf("%d: eating\n", self->id); goto putdown_rfork(self); } /* waiting for right fork */ __code hungry2(PhilsPtr self) { printf("%d: hungry2\n", self->id); goto pickup_rfork(self); } /* waiting for left fork */ __code hungry1(PhilsPtr self) { printf("%d: hungry1\n", self->id); goto pickup_lfork(self); } __code pickup_rfork(PhilsPtr self) { if (self->right_fork->owner == NULL) { printf("%d: pickup_rfork:%d\n", self->id, self->right_fork->id); self->right_fork->owner = self; goto eating(self); } else { goto hungry2(self); } } __code pickup_lfork(PhilsPtr self) { if (self->left_fork->owner == NULL) { printf("%d: pickup_lfork:%d\n", self->id, self->left_fork->id); self->left_fork->owner = self; goto pickup_rfork(self); } else { goto hungry1(self); } } __code thinking(PhilsPtr self) { printf("%d: thinking\n", self->id); goto hungry1(self); }