develop ← emezeske:pr/mac-realtime-start-failure
opened 03:20AM - 28 Sep 26 UTC
On macOS, a Thread whose startRealtimeThread call fails is left looking like it …is still running: isThreadRunning() stays true, stopThread() with no timeout blocks forever, and every later startRealtimeThread call returns false, so the thread can neither be retried nor cleaned up.
To reproduce on macOS, call startRealtimeThread (Thread::RealtimeOptions{}.withMaximumProcessingTimeMs (0.02)) on any Thread subclass. thread_policy_set rejects a computation time under 50 microseconds with KERN_INVALID_ARGUMENT, so the call returns false, but isThreadRunning() then returns true and stopThread() never returns.
createNativeThread stores the thread handle before the new thread attempts the realtime upgrade. When the upgrade fails, the thread returns without calling juce_threadEntryPoint, which is what closes the handle. This change closes the handle in createNativeThread when the thread reports that it failed to start, matching what the Windows implementation already does when setting the priority fails.