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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:13:28+00:00 2026-06-04T06:13:28+00:00

When threads are added to boost::thread_group like: boost::thread_group my_threads; boost::thread *t = new boost::thread(

  • 0

When threads are added to boost::thread_group like:

boost::thread_group my_threads;
boost::thread *t = new boost::thread( &someFunc );
my_threads.add_thread(th);

all the created boost::thread objects are deleted only when my_threads object is out of scope. But my program main thread spawns a lot of threads while execution. So if about 50 threads are already done, about 1,5Gb of memory is used by program and this memory is freed only on main process termination.

The question is: How to delete these boost::thread object when thread function is finished ?!

  • 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-04T06:13:29+00:00Added an answer on June 4, 2026 at 6:13 am

    You could do sth like this, but mind synchronization (it is better to use shared pointer to boost::thread_group instead of reference, unless you are sure, that thread group will live long enough):

    void someFunc(..., boost::thread_group & thg, boost::thread * thisTh)
    {
      // do sth
    
      thg.remove_thread(thisThr);
      delete thisTh; // we coud do this as thread of execution and boost::thread object are quite independent
    }
    
    void run()
    {
      boost::thread_group my_threads;
      boost::thread *t = new boost::thread(); // invalid handle, but we need some memory placeholder, so we could pass it to someFunc
      *t = boot::thread(
        boost::bind(&someFunc, boost::ref(my_threads), t)
      );
      my_threads.add_thread(t);
      // do not call join
    }
    

    You could also check at_thread_exit() function.

    Anyway, boost::thread objects should not weight 30 MB.

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

Sidebar

Related Questions

I have two threads, a producer thread that places objects into a generic List
I would like to avoid building a whole library for just boost::Thread . So
I'm trying to do something like this: using namespace boost::lambda; using boost::thread; int add(int
I have multiple threads who all need to write to the same Dictionary. I
My application uses several threads with well-defined names (i.e. not a thread pool with
I have two threads referencing the same variable -- the UI thread and a
I used 5 threads to create new InetSocketAddress and store them in queue, but
I have 2 threads and global Queue, one thread (t1) push the data and
I have multiple threads that share use of a semaphore. Thread A holds the
I have heard that the .NET 4 team has added new classes in the

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.