Skip to content
Snippets Groups Projects
Commit 2b183b54 authored by omah03's avatar omah03
Browse files

Update cars_1.c

parent 8f00bf33
No related branches found
No related tags found
1 merge request!4Übung2
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
...@@ -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;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment