Mercurial > hg > CbC > old > DPP
view main.cbc @ 0:d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 16 Dec 2015 15:16:11 +0900 |
parents | |
children | b15128ab0324 |
line wrap: on
line source
/* ** Dining Philosophers Problem's scheduler */ #include "dpp.h" #define NUM_PHILOSOPHER 5 /* A number of philosophers must be more than 2. */ code (*ret)(int); void *env; PhilsPtr phils_list = NULL; code run(PhilsPtr self) { goto thinking(self); } code init_final(PhilsPtr self) { self->right = phils_list; self->right_fork = phils_list->left_fork; printf("init all\n"); goto run(phils_list); } code init_phils2(PhilsPtr self, int count, int id) { PhilsPtr tmp_self; tmp_self = (PhilsPtr)malloc(sizeof(Phils)); if (!tmp_self) { goto die("Can't allocate Phils\n"); } self->right = tmp_self; tmp_self->id = id; tmp_self->right_fork = NULL; tmp_self->left_fork = self->right_fork; tmp_self->right = NULL; tmp_self->left = self; tmp_self->next = thinking; count--; id++; if (count == 0) { goto init_final(tmp_self); } else { goto init_fork2(tmp_self, count, id); } } code init_fork2(PhilsPtr self, int count, int id) { ForkPtr tmp_fork; tmp_fork = (ForkPtr)malloc(sizeof(Fork)); if (!tmp_fork) { goto die("Can't allocate Fork\n"); } tmp_fork->id = id; tmp_fork->owner = NULL; self->right_fork = tmp_fork; goto init_phils2(self, count, id); } code init_phils1(ForkPtr fork, int count, int id) { PhilsPtr self; self = (PhilsPtr)malloc(sizeof(Phils)); if (!self) { goto die("Can't allocate Phils\n"); } phils_list = self; self->id = id; self->right_fork = NULL; self->left_fork = fork; self->right = NULL; self->left = NULL; self->next = thinking; count--; id++; goto init_fork2(self, count, id); } code init_fork1(int count) { ForkPtr fork; int id = 1; fork = (ForkPtr)malloc(sizeof(Fork)); if (!fork) { goto die("Can't allocate Fork\n"); } fork->id = id; fork->owner = NULL; goto init_phils1(fork, count, id); } code die(char *err) { printf("%s\n", err); goto ret(1), env; } int main(void) { ret = return; env = environment; goto init_fork1(NUM_PHILOSOPHER); } /* end */