Skip to content
Snippets Groups Projects

Übung2

Open omah03 requested to merge omah03/alp4-repo-template:Übung2 into main
1 file
+ 4
1
Compare changes
  • Side-by-side
  • Inline
+ 4
1
@@ -45,7 +45,10 @@ void* func(void* ptr){
@@ -45,7 +45,10 @@ void* func(void* ptr){
crosses_counter++;
crosses_counter++;
unlock(car_id);
unlock(car_id);
//**********CRITICAL SECTION**********//
//**********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).
/*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;
return NULL;
}
}
Loading