My int main uses a while (1) loop to run my code. If I want to start continuous threads before I enter my while loop, would it look like this?
int main ()
{
boost::thread_group threads;
threads.create_thread (check_database);
while (1)
{
// main program
}
}
void check_database_and_plc ()
{
while (1)
{
// check database, and if it needs to take action, do so;
// this function / thread will never stop;
// it will continuously check a single value from mysql and take
// action based on that number (if 1, write to PLC, if 2, change
// screens, etc);
// also check plc for any errors, if there are any, tell int main
}
}
Therefore I have two while loops running at the same time. Is there a better way to do this? Thank you for your time.