Waiting in c++ method without blocking main thread.

Hi, I have a c++ method that is called asynchronously and which needs to wait for a certain number of frames to be executed (i.e. calls to TickComponent) before returning a value. I currently increment the frame count in the TickComponent method. I am trying to figure out how to:

  • Make sure the method does not return until the required number of frames has incremented by a given amount, the method does return a value;
  • Ensure the engine does not lockup during the call to my method (i.e. the method call should not prevent the engine from continuing its update loop that call TickComponent).

I have search for this, and seen people using Timer, but it is not clear to me how to apply this in my case.

Anyone has an idea how to approach this?

Thanks

Hi PierreSpace,

You could poll it, just in a loop in that thread, test for your condition, if it’s not met do a Sleep() for a certain amount of time, increment a timeout, if it’s above a certain amount, time out, or loop around again.

Simple approach is just put a tick counter in the Tick() of whatever needs the data. Then when it has waited the required number of ticks, query whatever has the data.

Pretty common use case for things like checking incoming async TCP / UDP data if you aren’t using the Unreal replication system.