Q:

Interleaving execution of two while loops

I have two sensors, that I need to monitor constantly. the inner working of the two sensors are different and I need to check both constantly as shown below.  
int sensorA(){
    while (true) {
    // read sensor A
    cout<<"sensorA \n";
  }
}
int sensorB(){
    while (true) {
    // read sensor B
    cout<<"sensorB \n";
  }
}

My question is how can I ensure the two sensors are read in interleaved manner? Like read sensorA then SensorB then Sensor A etc.

A:

Read both in the same loop?
int sensorA();
int sensorB();
while(true){
    //read A
    count<<"sensor A \n";
    //read B
    coutn<<"sensor B \n";
}

If you need them to be constantly read and cannot, for some reason, afford the delay between reads on a single sensor, then you'll need to create a thread for each sensor.

A:

(Euh, so my comment as an answer:)
Just read them one after the other, within the same loop.
while (1) {
    read(sensorA);
    read(sensorB);
}

something like the above pseudo-code will do the trick.

A:

You need to run them in separate threads.
Thread 1 would run one loop, while Thread 2 would run the other.
See 
void thread1fun()
{
  while (true) {
    // read sensor A
    cout<<"sensorA \n";
  }
}

void thread2fun()
{
  while (true) {
    // read sensor B
    cout<<"sensorB \n";
  }
}

int main()
{
    std::thread t1(thread1fun); 
    std::thread t2(thread2fun); 
    t1.join();
    t2.join();
}

NOTE
As pointed out in the comments, this only guarantees that both while loops will run continuously. In a "normal" architecture then the threads will both, on average, run roughly at the same "speed". However if the requirement is that the sensors are read strictly as follows {s1,s2,s1,s2....}, then this is not sufficient. In that case you would need a signalling system (events and waits) to guarantee that order. 
That would likely be inefficient if your sensors can be read very quickly.

