Skip to content
Snippets Groups Projects
Commit 8f00bf33 authored by omah03's avatar omah03
Browse files

Added useful comment and updated print statement

parent ba274dc3
No related branches found
No related tags found
1 merge request!4Übung2
......@@ -37,7 +37,7 @@ void* func(void* ptr){
while (crosses_counter < crosses){
lock(car_id);
while (car_on_bridge == Bridge_Capacity){}
printf("Car %d has crossed the bridge\n",car_id);
printf("Car %d is crossing the bridge\n",car_id);
car_on_bridge ++;
usleep(10000);
car_on_bridge --;
......@@ -45,6 +45,7 @@ void* func(void* ptr){
crosses_counter++;
unlock(car_id);
//**********CRITICAL SECTION**********//
//The thread acquires the lock before it enters the ciritical section. If there is a car on the bridge (another thread has the lock) then we wait. While the car is crossing, we increment he car_on_bridge by 1, reaching bridge capacity.We simulate the crossing bridge time using usleep.The car crosses, we decrement the car_on_bridge and print out a message that the car has crossed, then we increment the crosses_counter and release the lock so that it can be obtained by other cars(threads).
}
return NULL;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment