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 6757883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:42:31+00:00 2026-05-26T13:42:31+00:00

I have a project where we want to provide to use threads to speed

  • 0

I have a project where we want to provide to use threads to speed up everything.
We want to be able to call this function in individual threads:

Request& Filter::processRequest(Request& req)

Therefore I packed the function in lambda expression to have access to the return value.

I now get the following runtime error:

  glibc detected ... double free or corruption (!prev): ...

When I uncomment the line where I add the thread to the group everything works fine.

boost::thread_group thread;
for (std::set<boost::shared_ptr<Filter> >::iterator i = sources_.begin();
    i != sources_.end(); ++i) {
         Request ret
         thread.add_thread(new boost::thread(boost::lambda::var(ret) = 
            (*i)->processRequest(req)));
         req+=ret;
         ...
}
thread.join_all();

What can be the reason for this runtime error. Or is there another way to put this function in individual threads?

  • 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-05-26T13:42:31+00:00Added an answer on May 26, 2026 at 1:42 pm

    If this sort of technique were to work at all, you would need multiple ret values that you could stably reference (one for each thread of execution). And you’d have to wait until after your thread join completed until you used those values.

    A simple modification you can try would just be to make a vector outside of the loop of vector<Request> retValues…and then add an element to the vector each time you add_thread and pass a reference to that element. Then if you wait until after the join to use the values, perhaps it would work?

    boost::thread_group thread;
    vector<Request> retValues;
    for (std::set<boost::shared_ptr<Filter> >::iterator i = sources_.begin();
        i != sources_.end(); ++i) {
             retValues.push_back(0);
             thread.add_thread(new boost::thread(
                boost::lambda::var(retValues.back()) = 
                (*i)->processRequest(req)));
             ...
    }
    thread.join_all();
    // retValues safe to use here...
    

    (Note: Using boost::lambda is probably not necessary; you can use boost::bind to connect to a worker class that stores the result:

    Getting return value from a boost::threaded member function?

    …but really, no matter what you’ll need a separate variable per thread to store the result…whose lifetime lasts long enough for the thread to be able to write to it.)

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

Sidebar

Related Questions

I have project I want to upgrade to .Net4 and it use BackgroundCopyManager.dll. Anyone
I have a Java project in Netbeans and I want to use some classes
I have a project to do in PHP (5) and I want to use
I have a specific project in which I want to use either a scripting
I have this framework project kind of on the backburner where I want to
I have a project where I want to display overlays to locate people on
I have a project that I want to push to a Mercurial repository on
I have a project where I want to have checked arithmetic by default, except
I have a console project which I want to start with some parameters argc
I have a website project that I want to build using CruiseControl.net. On one

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.