Change where sleep is

This commit is contained in:
Isaac Shoebottom 2023-10-11 17:20:02 -03:00
parent 39d628cad2
commit 5418f83cae

View File

@ -41,7 +41,7 @@ void* dweller(void* arg) {
int time = RANDOM_WITHIN_RANGE(MIN_TIME_FOR_HOUSE_DWELLER, MAX_TIME_FOR_HOUSE_DWELLER, seed);
sleep(time);
write(houseFloor[WRITE_END], &weight, sizeof(int));
printf("House dweller %d produced a box that weights %d in %d units of time\n", id, weight, time);
printf("House dweller %d created a box that weights %d in %d units of time\n", id, weight, time);
}
printf("House dweller %d is done packing\n", id);
free(args);
@ -58,8 +58,8 @@ void* mover(void* arg) {
while (read(houseFloor[READ_END], &weight, sizeof(int)) > 0) {
int time = RANDOM_WITHIN_RANGE(MIN_TIME_FOR_MOVER, MAX_TIME_FOR_MOVER, seed);
sleep(time);
printf("Mover %d brought down a box of weight %d in %d units of time\n", id, weight, time);
write(nextToTrucks[WRITE_END], &weight, sizeof(int));
printf("Mover %d brought down a box of weight %d in %d units of time\n", id, weight, time);
}
printf("Mover %d is done moving\n", id);
free(args);
@ -91,9 +91,9 @@ void* trucker(void* arg) {
}
}
printf("Truck %d is not full\n", id);
int time = RANDOM_WITHIN_RANGE(MIN_TRIP_TIME/2, MAX_TRIP_TIME/2, seed); // One way trip, so half the time
sleep(time);
int time = RANDOM_WITHIN_RANGE(MIN_TRIP_TIME, MAX_TRIP_TIME, seed); // One way trip, so half the time
printf("Not full truck %d with load of %d units of mass departed. One way will take %d units of time\n", id, truckWeight, time);
sleep(time);
printf("Truck %d is finished\n", id);
free(args);
return NULL;