Exemple #1
0
//bartender simulation
void* bartender(){
    void* ret_val = 0;
    int tid = thread_getId();
    double amount =0;
    double buf_size =0;
    for(;;){
	struct Action* bartender_action = get_action();	
	if(bartender_action->action_type == DRINK_ORDER){
	    struct Cup* current_cup = get_clean_cup();
	    //need to write to file intsead of screen TODO
	    printf(1,"Bartender %d is making drink with cup %d\n",tid,current_cup->id);
	    serve_drink(current_cup);
	}
	else if(bartender_action->action_type == RETURN_CUP){
	  struct Cup* current_cup = bartender_action->cup;  
	  return_cup(current_cup);
	  //need to write to file intsead of screen TODO
	  printf(1,"Bartender %d returned cup %d\n",tid,current_cup->id);
	  
	  amount = DBB->full->value;
	  buf_size = DBB->buffer_size;
	  
	  if(amount/buf_size >= 0.6){
	    printf(1,"Go Clean Boy %d\n");
	    binary_semaphore_up(cup_boy_lock);
	    }
	if(bartender_action->action_type == GO_HOME){
	  free(bartender_action);
	  thread_exit(ret_val);
	}
      }
	free(bartender_action);
    }
    return 0;
}
Exemple #2
0
void* bartender_work(){
	while(1){
		struct Action* action=get_action();
		
		if(action->type == 1){
			struct Cup* cup=get_clean_cup();
			
			printf(fileOut, "Bartender %d is making drink with cup %d\n",
				thread_getId(), cup->id);
			
			action->cup=cup;
			serve_drink(cup);
		} else {
			return_cup(action->cup);
			printf(fileOut, "Bartender %d returned cup %d\n",
					 thread_getId(), action->cup->id);
		}
		
		free(action);
	}
	return 0;
}