Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8265471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:49:00+00:00 2026-06-08T04:49:00+00:00

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*,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:49:02+00:00Added an answer on June 8, 2026 at 4:49 am

    Your code invalidates vector::iterator i by calling

    wait.erase(i);
    

    It then increments the invalid i and uses it to determine if it should break out of the for loop.

    You should instead use std::partition(). That entire for-loop could be replaced with:

    traveling running_jobs = 
                       std::partition( wait.begin(), wait.end(), is_not_running );
    
    running_jobs.insert( running_jobs, wait.end() );
    
    wait.erase( running_jobs, wait.end() );
    

    is_not_running would be a function of your creation. This would also reduce the complexity from O(n2) to O(n).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this JSON response string: {d:{\ID_usuario\:\000130\,\Nombre\:null,\Vipxlo\:0,\Provmun\:null,\Descuentos\:null,\Listaviplocal\:null}}` With this code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
I have this code: private void timer1_Tick(object sender, EventArgs e) { #region BaseAddress Process[]
I have this code private void writeReport(IReport report, string reportName) { string reportString =
Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
I have this code: @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { GLES20.glClearColor(0, 0,
I have this segment of code: - (void)setTableView:(UITableView *)tableView { tableView = tableView; }
i have this code public interface Interfcae1 { void OP1(); } public interface Interfcae2
I have this code: //choosed a picture public void onActivityResult(int requestCode, int resultCode, Intent
I have this code: hubSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.