Skip to content

Commit

Permalink
different sync strat
Browse files Browse the repository at this point in the history
  • Loading branch information
debaetsd committed Feb 25, 2021
1 parent d51c77e commit a2ea041
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/lib/IlmThread/IlmThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,18 @@ DefaultThreadPoolProvider::setNumThreads (int count)
std::lock_guard<std::mutex> lock (_data.threadMutex);

size_t desired = static_cast<size_t>(count);
size_t toSync = 0;
if (desired > _data.threads.size())
{
//
// Add more threads
//

while (_data.threads.size() < desired)
while (_data.threads.size () < desired)
{
_data.threads.push_back (new DefaultWorkerThread (&_data));
toSync++;
}
}
else if ((size_t)count < _data.threads.size())
{
Expand All @@ -325,11 +329,23 @@ DefaultThreadPoolProvider::setNumThreads (int count)
// Add in new threads
//

while (_data.threads.size() < desired)
while (_data.threads.size () < desired)
{
_data.threads.push_back (new DefaultWorkerThread (&_data));
toSync++;
}
}

_data.hasThreads = !(_data.threads.empty());

// make sure the threads have actually started
for (size_t i = 0; i != toSync; ++i)
{
if (_data.threads[i]->joinable ())
{
_data.threadSemaphore.wait ();
}
}
}

void
Expand Down Expand Up @@ -393,7 +409,7 @@ DefaultThreadPoolProvider::finish ()
if (_data.threads[i]->joinable())
{
_data.taskSemaphore.post();
_data.threadSemaphore.wait();
// _data.threadSemaphore.wait();
}
}

Expand Down

0 comments on commit a2ea041

Please sign in to comment.