ThreadPool with 1 thread


#1

I don’t understand this code:

 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:

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

#2

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.


#3

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