Concurrency/3.Mutexes_Locks/L3_Project/src/Intersection.cpp
void Intersection::addVehicleToQueue(std::shared_ptr<Vehicle> vehicle)
{
    // L3.3 : Ensure that the text output locks the console as a shared resource. Use the mutex _mtxCout you have added to the base class TrafficObject in the previous task. Make sure that in between the two calls to std-cout at the beginning and at the end of addVehicleToQueue the lock is not held. 

    std::cout << "Intersection #" << _id << "::addVehicleToQueue: thread id = " << std::this_thread::get_id() << std::endl;

    // add new vehicle to the end of the waiting line
    std::promise<void> prmsVehicleAllowedToEnter;
    std::future<void> ftrVehicleAllowedToEnter = prmsVehicleAllowedToEnter.get_future();
    _waitingVehicles.pushBack(vehicle, std::move(prmsVehicleAllowedToEnter));

    // wait until the vehicle is allowed to enter
    ftrVehicleAllowedToEnter.wait();
    std::cout << "Intersection #" << _id << ": Vehicle #" << vehicle->getID() << " is granted entry." << std::endl;
}
// adds a new vehicle to the queue and returns once the vehicle is allowed to enter
adds a new vehicle to the queue and returns once the vehicle is allowed to enter
adds a new vehicle to the queue and returns once the vehicle is allowed to enter
void Intersection::addVehicleToQueue(std::shared_ptr<Vehicle> vehicle)
{
    std::cout << "Intersection #" << _id << "::addVehicleToQueue: thread id = " << std::this_thread::get_id() << std::endl;
    std::promise<void> prmsVehicleAllowedToEnter;
    std::future<void> ftrVehicleAllowedToEnter = prmsVehicleAllowedToEnter.get_future();
    _waitingVehicles.pushBack(vehicle, std::move(prmsVehicleAllowedToEnter));
    ftrVehicleAllowedToEnter.wait();
    std::cout << "Intersection #" << _id << ": Vehicle #" << vehicle->getID() << " is granted entry." << std::endl;
}
void Intersection :: addVehicleToQueue ( std :: shared_ptr < Vehicle > vehicle ) { std :: cout << " " << _id << " " << std :: this_thread :: get_id ( ) << std :: endl ; std :: promise < void > prmsVehicleAllowedToEnter ; std :: future < void > ftrVehicleAllowedToEnter = prmsVehicleAllowedToEnter . get_future ( ) ; _waitingVehicles . pushBack ( vehicle , std :: move ( prmsVehicleAllowedToEnter ) ) ; ftrVehicleAllowedToEnter . wait ( ) ; std :: cout << " " << _id << " " << vehicle -> getID ( ) << " " << std :: endl ; }
adds a new vehicle to the queue and returns once the vehicle is allowed to enter
adds a new vehicle to the queue and returns once the vehicle is allowed to enter
// L3.3 : Ensure that the text output locks the console as a shared resource. Use the mutex _mtxCout you have added to the base class TrafficObject in the previous task. Make sure that in between the two calls to std-cout at the beginning and at the end of addVehicleToQueue the lock is not held.  // add new vehicle to the end of the waiting line // wait until the vehicle is allowed to enter