Make thread wait until another thread has changed a variable. How?

somawheels
Tue, 22 Jun 2021 00:00:55 +0000
Editor Scripting

I have a struct in thread1. I pass the struct to thread 2. I want thread 1 to wait until thread 2 has modified the struct.

I have tried doing a while loop, which makes the thread sleep until the variable in the struct has changed:

  while (MyStruct->variable== nullptr) {//do nothing}

however even after the variable has changed, the loop continues to sleep.
I think to make the while loop work properly, i would have to use an FThreadSafeBool. However this is not something UStructs can contain. What should I do in this situation?

6 posts - 1 participant