Best way to kill a long-running directory thread?


#1

Hello, Jucies.

In order to keep liveness in my program, I do all my directory fetching in separate threads (in particular, opening my personal itunes directory would freeze my fast machine for several seconds).

Unfortunately, if you start the program and then close it fairly quickly, you get a crash on shutdown.

The cause is obvious - I call stopThread(1000) on the thread, but the directory getting function (which is part of Juce) takes longer than 1000 milliseconds to complete, and then I run into the jassertfalse in stopThread.

Now, I can simply up that 1000ms number - but to what? I expect this to run on some fairly old machines, and I don’t want it to hang indefinitely.

Or I could wrap the destructor in a catch block - but I seem to remember having issues catching “assert” statements before.

And I really don’t care if I leak or lock because I’m at the very tail end of my shutdown sequence. (Well, I’d care if a lock prevented me from completing shutdown.)

Or I could declare juce_killThread and call that on shutdown only.

Thoughts?


#2

If you use a DirectoryIterator to find the files, you could just check threadShouldExit() before each call to DirectoryIterator::next()?


#3

Aha! DirectoryIterator!

Logical, will implement. ty ty!