Let's say we have a parent class called Sensor
. Mobile robot has a variety of sensors (e.g cam, sonar, laser, GPS, ... etc). Each sensor has its own thread and it provides the Robot with noisy measurements. I would like to simulate this scenario, therefore the code might look like the following
class Robot
{
update()
{
mSensor[i]->update();
}
Sensor *mSensor;
}
class Sensor
{
update();
}
class GPS : public Sensor
{
Thread mThread();
update();
}
class CAM : public Sensor
{
Thread mThread();
update();
}
In the main function, basically I need to create a Robot object, therefore
#include "Robot.h"
int main()
{
Robot robo;
while( true ){
robot.update();
}
}
My question is how can I guarantee the threads of Sensors are terminated by only terminating the robo object? Do I have to go through all sensors objects by some kind of loop in parent destructor?