So I’ve been experimenting with threads in JUCE, I’m just using the native C++ threads because I’m more familiar with them. (Is it better practice to use JUCE threads?)
Anyway, I’ve got a simple method that creates a thread like this:
void DrawGraphics::engageClock()
{
mPlayState = PlayState::Playing;
unsigned int rate = 2;
DBG("main thread : " << std::hash<std::thread::id>{}(std::this_thread::get_id()));
std::thread clockWork(&DrawGraphics::clock, this, rate);
}
Which just starts an audio clock on another thread as seen below…
void DrawGraphics::clock(unsigned int rate) // accepts an integer as Hz
{
const MessageManagerLock mml(Thread::getCurrentThread());
if (mml.lockWasGained())
{
DBG("mml lock succesful");
}
else
{
DBG("mml locked unsuccesful");
}
... DO CLOCK STUFF
}
It seems to work fine but then in the console this gets printed and the program crashes:
main thread : 15735606657672724526
Debug Error!
Program: ...afix-0_2\Builds\VisualStudio2017\x64\Debug\App\grafix-0_2.exe
abort() has been called
(Press Retry to debug the application)
mml gained
DSP thread : 15675618735505290966
So two different threads are clearly created but abort() is being called once the MessageManagerLock was gained.
Does anyone know why this could be? Should I just be using JUCE threads?
Thanks