mirror of
				https://gitlab.com/klmp200/LO41.git
				synced 2025-10-31 17:23:05 +00:00 
			
		
		
		
	Les ascenseurs en premier
This commit is contained in:
		| @@ -11,7 +11,7 @@ GETTER(Resident, int, apartment_floor); | ||||
|  | ||||
| void * runnable_Resident(void * void_this){ | ||||
| 	Resident * this = (Resident*) void_this; | ||||
| 	printf("Je suis le RESIDENT %s et je suis a l'etage %d en direction de l'etage %d\n", | ||||
| 	printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n", | ||||
| 		this->name, this->apartment_floor, this->destination); | ||||
| 	return NULL; | ||||
| } | ||||
|   | ||||
| @@ -29,15 +29,12 @@ int call_elevator_SharedData(THIS(SharedData), int starting_floor, int destinati | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
| /* void * runnable_type(void* void_this) */ | ||||
|  | ||||
| void start_thread_SharedData(THIS(SharedData), void * (*thread)(void *), void * data, int thread_number){ | ||||
| 	pthread_create(&this->threads[thread_number], 0, thread, data); | ||||
| } | ||||
|  | ||||
| void start_all_threads_SharedData(THIS(SharedData)){ | ||||
| 	int i = 0; | ||||
| 	int elevator_index; | ||||
| 	Element * current = NULL; | ||||
| 	List * residents = NULL; | ||||
| 	List * visitors = NULL; | ||||
| @@ -51,6 +48,11 @@ void start_all_threads_SharedData(THIS(SharedData)){ | ||||
| 			this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB; | ||||
| 			this->threads = malloc_or_die(sizeof(pthread_t) * this->threads_nb); | ||||
|  | ||||
| 			/* starts threading elevators */ | ||||
| 			for (i=0; i<ELEVATOR_NB; i++) | ||||
| 				this->start_thread(this, this->main_building->elevators[i]->runnable, | ||||
| 								   this->main_building->elevators[i], i); | ||||
|  | ||||
| 			/* starts threading visitors */ | ||||
| 			current = visitors->get_head(visitors); | ||||
| 			while (current != NULL){ | ||||
| @@ -66,13 +68,6 @@ void start_all_threads_SharedData(THIS(SharedData)){ | ||||
| 				current = current->get_next(current); | ||||
| 				i++; | ||||
| 			} | ||||
|  | ||||
| 			/* starts threading elevators */ | ||||
| 			for (elevator_index=0; elevator_index<ELEVATOR_NB; elevator_index++){ | ||||
| 				this->start_thread(this, this->main_building->elevators[elevator_index]->runnable, | ||||
| 					this->main_building->elevators[elevator_index], i); | ||||
| 				i++; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user