Thread doesn't start on MAC

Hey guys!

In a standalone application, I want to show a loading screen (DocumentWindow) before the main DocumentWindow loads.
Soo, my Main.cpp contains the following:

MainProgramApplication-> derived from: juce:: JUCEApplication juce:: Thread, juce:: Thread ::Listener

MainProgramApplication::run():
mainWindow.reset(new MainWindow())
signalThreadShouldExit()

MainProgramApplication::initialise():
loadingWindow.reset(new ...)
startThread()

MainProgramApplication::exitSignalSent():
loadingWindow->setVisible(false)

So the result on Windows: works perfectly, the loading screen disappears when the mainWindow loaded and thread exit, and the mainWindow shows up.

Result on Mac: startThread() doesn’t run, and something happens similar to you write wait(infinity) before startThread(), but its not freezed, just waiting.

What should I do?

Regards,
Ervin

Can’t read your code, please repost with triple ticks surrounding it

void SoYourCodeIsReadable ()
{
    // thank you
}

its only pseudo, but i did the change, thanks.

The first implementation issue is that you call signalThreadShouldExit immediately, which will cause your exit thread exit listener to be called.

void Thread::signalThreadShouldExit()
{
    shouldExit = 1;
    listeners.call ([] (Listener& l) { l.exitSignalSent(); });
}

A thread might be heavy handed for this, maybe something like AsyncUpdater would be better suited. I would approach it more like this, pass a lambda into the main window, and call it when it is done with the ctor (or maybe store it and call it in a derived visibilityChanged or something similar). This explicitly states what is happening, and is much easier to reason about.

You shouldn’t control a Thread state from its own change callbacks, you’re probably creating a race condition.

See https://docs.juce.com/master/classSplashScreen.html

Hey! Thanks for the advice, I discovered the thread starts, but my MainWindow contains components and some of the components starts a thread too. Could it be the problem? I’ve got the loading screen on mac but the construction of the MainWindow doesn’t finish, so the thread is freezed.

Providing threads don’t share any data or control each other, no. You can start as many threads as you want. You can inspect each Thread’s call stack and see where your locked Thread is waiting.