Continuation style call like .NET async-await in C++?

190 views Asked by At

I'm working on a C++ project where I have to implement code some custom radio communication.

This obviously cannot block the main thread at any point by waiting for a join(), a Future.get() etc. , but I'm really struggling to figure out how to do this without getting into thread hell with mutex locking all over the place to cripple the performance.

Is there any easy way to do this like aync-await in .NET?

The architecture of the program is basically like this:

int main()
{
   App = new APP();
   Ui = new UI();
   Statemachine = new StateMachine(); 

   for(;;)
   {
      App->update();
   }
}

// The update fucntion of the App class
App::update()
{
   Ui-> update();
   Statemachine->CurrentState->update();;
}

// The update function of the state machine
CurrentState::update()
{
   // Must not block thread 
   string receivedText = Radio->GetDatafromslowRadioAsync();

   // Immediately continue to execute this
   ImportantFunction();
   AnotherImportantFucntion();
}

As of now the radio runs in a separate thread, continuously sending messages from a queue that can be filled from the main thread.

0

There are 0 answers