1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Allow to specify the stack size for each thread in a thread pool explicitly, by adding an optional parameter to the constructors of ThreadPool and ThreadPoolThread.

This commit is contained in:
stefan 2016-10-26 19:18:20 +02:00
parent 439ecc391b
commit 4aa0f311e0
2 changed files with 12 additions and 8 deletions

View file

@ -29,8 +29,8 @@
class ThreadPool::ThreadPoolThread : public Thread
{
public:
ThreadPoolThread (ThreadPool& p)
: Thread ("Pool"), currentJob (nullptr), pool (p)
ThreadPoolThread (ThreadPool& p, size_t stackSize = 0)
: Thread ("Pool", stackSize), currentJob (nullptr), pool (p)
{
}
@ -85,11 +85,11 @@ ThreadPoolJob* ThreadPoolJob::getCurrentThreadPoolJob()
}
//==============================================================================
ThreadPool::ThreadPool (const int numThreads)
ThreadPool::ThreadPool (const int numThreads, size_t threadStackSize)
{
jassert (numThreads > 0); // not much point having a pool without any threads!
createThreads (numThreads);
createThreads (numThreads, threadStackSize);
}
ThreadPool::ThreadPool()
@ -103,10 +103,10 @@ ThreadPool::~ThreadPool()
stopThreads();
}
void ThreadPool::createThreads (int numThreads)
void ThreadPool::createThreads (int numThreads, size_t threadStackSize)
{
for (int i = jmax (1, numThreads); --i >= 0;)
threads.add (new ThreadPoolThread (*this));
threads.add (new ThreadPoolThread (*this, threadStackSize));
for (int i = threads.size(); --i >= 0;)
threads.getUnchecked(i)->startThread();

View file

@ -152,10 +152,14 @@ public:
//==============================================================================
/** Creates a thread pool.
Once you've created a pool, you can give it some jobs by calling addJob().
@param numberOfThreads the number of threads to run. These will be started
immediately, and will run until the pool is deleted.
@param threadStackSize the size of the stack of each thread. If this value
is zero then the default stack size of the OS will
be used.
*/
ThreadPool (int numberOfThreads);
ThreadPool (int numberOfThreads, size_t threadStackSize = 0);
/** Creates a thread pool with one thread per CPU core.
Once you've created a pool, you can give it some jobs by calling addJob().
@ -309,7 +313,7 @@ private:
bool runNextJob (ThreadPoolThread&);
ThreadPoolJob* pickNextJobToRun();
void addToDeleteList (OwnedArray<ThreadPoolJob>&, ThreadPoolJob*) const;
void createThreads (int numThreads);
void createThreads (int numThreads, size_t threadStackSize = 0);
void stopThreads();
// Note that this method has changed, and no longer has a parameter to indicate