// student simulation void* student(){ enter_bar(); int tid = thread_getId(); int i; for(i = 0; i < tid % 5; i++){ printf(1,"Student %d is for i: %d\n",tid,i+1); struct Action* drink_action = malloc(sizeof(struct Action)); memset(drink_action,0,sizeof(struct Action)); drink_action->action_type = DRINK_ORDER; drink_action->cup = 0; drink_action->tid = tid; place_action(drink_action);//Order a Drink struct Cup * cup = get_drink(); //get the drink from the BB //need to write to file intsead of screen TODO printf(1,"Student %d is having his %d drink, with cup %d\n",tid,i+1,cup->id); sleep(1); struct Action* return_action = malloc(sizeof(struct Action)); memset(return_action,0,sizeof(struct Action)); return_action->action_type = RETURN_CUP; return_action->cup=cup; return_action->tid = tid; place_action(return_action); } //need to write to file intsead of screen TODO printf(1,"Student %d is drunk, and trying to go home\n",thread_getId()); leave_bar(); thread_exit(0); return 0; }
void* student_work(){ int k=thread_getId() % 5; enter_bar(); int i; for(i=0; i<k; i++){ // create action printf(1, "creating order...\n"); struct Action* action=malloc(sizeof(struct Action)); action->type=1; action->cup=0; action->tid=thread_getId(); place_action(action); printf(1, "placed order\n"); struct Cup* cup=get_drink(); printf(fileOut, "Student %d is having his %d drink, with cup %d\n", thread_getId(), i, cup->id); sleep(1); action=malloc(sizeof(struct Action)); action->type=2; action->cup=cup; action->tid=thread_getId(); printf(1, "returning cup...\n"); place_action(action); } printf(fileOut, "Student %d is drunk, and trying to go home", thread_getId()); leave_bar(); printf(1, "left bar... left=%d\n", left_counter); thread_exit(&i); return 0; }