@@ -297,8 +297,8 @@ using DeferredFiles = std::vector<DeferredFile>;
297297// the process is not stalled waiting on disk buffer i/o.
298298void multiThreadedPageInBackground (const DeferredFiles &deferred) {
299299 static size_t pageSize = Process::getPageSizeEstimate (), totalBytes;
300+ static std::mutex mutex;
300301 size_t index = 0 ;
301- std::mutex mutex;
302302
303303 parallelFor (0 , config->readThreads , [&](size_t I) {
304304 while (true ) {
@@ -324,34 +324,34 @@ void multiThreadedPageInBackground(const DeferredFiles &deferred) {
324324 << deferred.size () << " \n " ;
325325}
326326
327- static void multiThreadedPageIn (const DeferredFiles &deferred) {
327+ static void
328+ multiThreadedPageIn (const DeferredFiles &deferred = DeferredFiles()) {
328329 static std::thread *running;
329330 static std::mutex mutex;
330331 static std::deque<DeferredFiles *> queue;
331332
332333 mutex.lock ();
333- if (running) {
334+ if (running && (queue. empty () || deferred. empty ()) ) {
334335 running->join ();
335336 delete running;
336337 running = nullptr ;
337338 }
338339
339340 if (!deferred.empty ()) {
340341 queue.emplace_back (new DeferredFiles (deferred));
341- running = new std::thread ([&]() {
342- while ( true ) {
342+ if (!running)
343+ running = new std::thread ([&]( ) {
343344 mutex.lock ();
344- if (queue.empty ()) {
345+ while (!queue.empty ()) {
346+ DeferredFiles *deferred = queue.front ();
345347 mutex.unlock ();
346- return ;
348+ multiThreadedPageInBackground (*deferred);
349+ delete deferred;
350+ mutex.lock ();
351+ queue.pop_front ();
347352 }
348- DeferredFiles *deferred = queue.front ();
349- queue.pop_front ();
350353 mutex.unlock ();
351- multiThreadedPageInBackground (*deferred);
352- delete deferred;
353- }
354- });
354+ });
355355 }
356356 mutex.unlock ();
357357}
@@ -1413,8 +1413,8 @@ static void createFiles(const InputArgList &args) {
14131413 archive->addLazySymbols ();
14141414 }
14151415
1416- // flush threads
1417- multiThreadedPageIn (DeferredFiles () );
1416+ // reap threads
1417+ // multiThreadedPageIn();
14181418 }
14191419}
14201420
0 commit comments