Josh Posted August 24, 2021 Share Posted August 24, 2021 This new feature takes something that is very very difficult and makes it very very easy. You can use this to set up block / wait operations in threads. In this example, the second thread blocks until the user presses the space key, signaling the condition and allowing the second thread to proceed and return. #include "UltraEngine.h" using namespace UltraEngine; shared_ptr<Object> EntryPoint(shared_ptr<Object> extra) { //Cast to Condition object auto cond = extra->As<Condition>(); //Wait for signaled state cond->Wait(); return NULL; } int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a condition auto cond = CreateCondition(); //Create a thread auto thread = CreateThread(EntryPoint, cond); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { //Press space to signal the condition if (window->KeyHit(KEY_SPACE)) cond->Signal(); //Detect thread finished if (thread->GetState() == THREAD_FINISHED) { Notify("Thread finished!"); return 0; } Sleep(1); } return 0; } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.