# PR: Close the thread handle when a realtime thread fails to start

**URL:** <https://forum.juce.com/t/pr-close-the-thread-handle-when-a-realtime-thread-fails-to-start/69599>\
**Category:** MacOSX and iOS\
**Created:** [September 28, 2026, 3:38am UTC](https://forum.juce.com/t/pr-close-the-thread-handle-when-a-realtime-thread-fails-to-start/69599 "2026-09-28T03:38:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![emezeske](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/emezeske/32/15528_2.png) [@emezeske](https://forum.juce.com/u/emezeske)\
**Post date:** [September 28, 2026, 3:38am UTC](https://forum.juce.com/t/pr-close-the-thread-handle-when-a-realtime-thread-fails-to-start/69599/1 "2026-09-28T03:38:15Z")

</div>

> <https://github.com/juce-framework/JUCE/pull/1755>
>
> 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.
