The way my current is structured at the moment, I need to add a ThreadPoolJob to a ThreadPool in the destructor of a statically allocated object and I’m running into trouble.
I’m running on Windows but I think this is a platform-independent issue.
I get an access violation in CriticalSection::enter with a stack track like this:
tu_gn-test.exe!juce::CriticalSection::enter() Line 79 + 0xc bytes
tu_gn-test.exe!juce::Thread::threadEntryPoint(juce::Thread * const hread=0x00af6e80) Line 56
tu_gn-test.exe!juce::juce_threadEntryPoint(void * userData=0x00af6e80) Line 88 + 0x9 bytes
tu_gn-test.exe!juce::threadEntryProc(void * userData=0x00af6e80) Line 126 + 0x9 bytes
I think what’s happening is the statically allocated objects in juce_Thread.cpp:
static VoidArray runningThreads (4);
static CriticalSection runningThreadsLock;
are getting destroyed before my destructor runs.
Can you suggest a way to ensure that these objects stay around long enough for my destructor to run?
Thanks for your help.