c++ tuples, vector and threads code
===

I have this code:

       void threaded_function(Model_factory &mf, ppa::Node *root)
    {
 
      boost::mutex::scoped_lock lock(result_mutex);
      typedef  vector<boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> >
      ::iterator traveling;
      
      if(!running_jobs.empty())
      {
          cout << "size of running " << running_jobs.size() << endl;
          boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> tuple_to_check = 
          running_jobs.front();
          running_jobs.pop();
          
          cout << "poping this object from running_jobs" << tuple_to_check << endl;
          cout << "new size of running " << running_jobs.size() << endl;
          
          lock.unlock();
          ppa::Node *tuplets_father = boost::get<0>(tuple_to_check);
          ppa::Node *first_son = boost::get<1>(tuple_to_check);
          ppa::Node *second_son = boost::get<2>(tuple_to_check);
          bool is_this_done = boost::get<3>(tuple_to_check);
          
          tuplets_father->start_alignment_new(&mf);
          
          lock.lock();
          cout << "size of the wait " << wait.size() << endl;
          
           boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> new_tuple
           = boost::make_tuple(tuplets_father, first_son, second_son, true);
           wait.push_back(new_tuple);
           cout << "pushing this object to waiting list" << new_tuple << endl;

Space to not have to scroll   

           cout << "new size of the wait " << wait.size() << endl;  


         lock.unlock();
        
         lock.lock();
           
           for(traveling i = wait.begin(); i != wait.end(); i++)
          {
              if(boost::get<3>(*i) == true)
              {
                

                  cout << "found in here pushing to running jobs " << *i <<  endl;
                  boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool>  tuple = *i;
                  wait.erase(i);
                  running_jobs.push(tuple);
                  
                
                  
              }
          }
           lock.unlock();
           
      } 
      
      else
      {
          
          boost::this_thread::yield();
          
      } 
  
 And this is a piece of my output:

     found in here pushing to running jobs (0 0x1dd00000142 0xffffffff00000143 1)    
     found in here pushing to running jobs (0 0 0 66)                                
    found in here pushing to running jobs (0 0 0x1e000000142 67)                    
    found in here pushing to running jobs (0 0x1e100000142 0xffffffff00000143 1)    
    found in here pushing to running jobs (0 0 0 66)                                
    found in here pushing to running jobs (0 0 0x1e400000142 67)                    
    found in here pushing to running jobs (0 0x1e500000142 0xffffffff00000143 1)    
    found in here pushing to running jobs (0 0 0 66)                                
    found in here pushing to running jobs (0 0 0x1e800000142 67)                    
    found in here pushing to running jobs (0 0x1e900000142 0xffffffff00000143 1)    
    found in here pushing to running jobs (0 0 0 66)                                
    found in here pushing to running jobs (0 0 0x1ec00000142 67)

It will go forever, and I wonder where is the mistake, is it with the logic? Most likely yes, but I could use some new pair of eyes, thanks.
     