# ThreadPool with 1 thread

**URL:** <https://forum.juce.com/t/threadpool-with-1-thread/5245>\
**Category:** General JUCE discussion\
**Created:** [May 6, 2010, 9:19am UTC](https://forum.juce.com/t/threadpool-with-1-thread/5245 "2010-05-06T09:19:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [May 6, 2010, 9:19am UTC](https://forum.juce.com/t/threadpool-with-1-thread/5245/1 "2010-05-06T09:19:53Z")

</div>

I don’t understand this code:

```auto
 void ThreadPoolThread::run()
    {
        while (! threadShouldExit())
        {
            if (! pool.runNextJob())
                wait (500); // Here, what's for ?
        }
    }
```

My jobs do very fast and small things, but it’s slow to close.  
Maybe a lower value would be more appropriate ? Or this:

```auto
 void ThreadPoolThread::run()
    {
        while (! threadShouldExit())
        {
            if (! pool.runNextJob())
            {
                for (int i = 0; i < 5; i++)
                {
                     if (threadShouldExit()) break;
                     wait (100); // Here, what's for ?
                }
            }
        }
    }
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 6, 2010, 1:12pm UTC](https://forum.juce.com/t/threadpool-with-1-thread/5245/2 "2010-05-06T13:12:32Z")

</div>

If the thread runs out of things to do, it waits rather than spinning and burning cpu. When you add another job, notify() will be called, and it’ll wake up immediately and do it.

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [May 6, 2010, 1:23pm UTC](https://forum.juce.com/t/threadpool-with-1-thread/5245/3 "2010-05-06T13:23:46Z")

</div>

Ok, so the slow closing doesn’t comes from this then… I’ll continue searching.
