# Thread - stopThread

**URL:** <https://forum.juce.com/t/thread-stopthread/42603>\
**Category:** General JUCE discussion\
**Created:** [November 5, 2020, 5:35pm UTC](https://forum.juce.com/t/thread-stopthread/42603 "2020-11-05T17:35:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [November 5, 2020, 5:35pm UTC](https://forum.juce.com/t/thread-stopthread/42603/1 "2020-11-05T17:35:15Z")

</div>

Is there a situation where not calling stopThread before destruction is acceptable? I think probably not and maybe it’d be good to assert if the Thread destructor is called and stopThread hasn’t been called with a suitable timeout whether or not the thread is still running…

Certainly we use it all over the place and pretty much it’s bug if stopThread wasn’t called manually with a suitable timeout.

Can anyone think of a situation where it’d be wrong to assert on failure to call stopThread?

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [January 23, 2023, 1:07pm UTC](https://forum.juce.com/t/thread-stopthread/42603/2 "2023-01-23T13:07:57Z")

</div>

+1 !!

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [January 23, 2023, 6:56pm UTC](https://forum.juce.com/t/thread-stopthread/42603/3 "2023-01-23T18:56:33Z")

</div>

How would you determine “a suitable timeout”, and what would the assert look like for that requirement?

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [January 24, 2023, 9:41am UTC](https://forum.juce.com/t/thread-stopthread/42603/4 "2023-01-24T09:41:26Z")

</div>

The assert was to check that stopThread was called on destruction at all really. Otherwise you can go on assuming your thread will have stopped say by the time the app quits and not have stopThread in there - and then you’ve just got a bug waiting to happen.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [January 24, 2023, 10:08am UTC](https://forum.juce.com/t/thread-stopthread/42603/5 "2023-01-24T10:08:50Z")

</div>

> [@jimc](#):
>
> Is there a situation where not calling stopThread before destruction is acceptable? I think probably not and maybe it’d be good to assert if the Thread destructor is called and stopThread hasn’t been called with a suitable timeout whether or not the thread is still running…

The problem is, that if you get into the destructor of `juce::Thread`, it is already too late to call stopThread or to wait, because the thread is running a virtual function.

It needs to be handled in your sub-class.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [January 24, 2023, 10:09am UTC](https://forum.juce.com/t/thread-stopthread/42603/6 "2023-01-24T10:09:15Z")

</div>

Yes, so the assert is “has stopThread already been called”
