Ticket #2067: 2067.1.patch

File 2067.1.patch, 1.3 KB (added by mheyman@…, 13 years ago)

thread_group releases mutex while calling join()

  • thread.hpp

    old new  
    530530            }
    531531        }
    532532       
    533533        void join_all()
    534534        {
    535             boost::lock_guard<mutex> guard(m);
    536            
    537             for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
    538                 it!=end;
    539                 ++it)
     535            std::list<thread*> joined;
     536            for(;;)
    540537            {
    541                 (*it)->join();
     538                thread* t; // thread to join while mutex not held
     539                {
     540                    boost::lock_guard<mutex> guard(m);
     541
     542                    for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();;++it)
     543                    {
     544                        if(it=end)
     545                        {
     546                            return;
     547                        }
     548                        std::list<thread*>::iterator const j=std::find(joined.begin(),joined.end(),*it);
     549                        if(j==joined.end())
     550                        {
     551                            t = *it;
     552                            break;
     553                        }
     554                    }
     555                }
     556                t->join();
    542557            }
    543558        }
    544559       
    545560        void interrupt_all()
    546561        {