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

  • Home
  • SEARCH
  • 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 8411259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:23:23+00:00 2026-06-10T00:23:23+00:00

I found that boost thread overhead has three order of magnitude timing overhead in

  • 0

I found that boost thread overhead has three order of magnitude timing overhead in the following simple program. Is there anyway to reduce this overhead and speedup the fooThread() call ?

#include <iostream>
#include <time.h>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
typedef uint64_t tick_t;
#define rdtscll(val) do { \
    unsigned int __a,__d; \
    __asm__ __volatile__("rdtsc" : "=a" (__a), "=d" (__d)); \
        (val) = ((unsigned long long)__a) | (((unsigned long long)__d)<<32); \
    } while(0)


class baseClass {
 public:
   void foo(){
             //Do nothing 
        }
       void threadFoo(){
          threadObjOne = boost::thread(&baseClass::foo, this);
              threadObjOne.join();
   }

 private:
   boost::thread threadObjOne;
 };

int main(){
   std::cout<< "main startup"<<std::endl; 
   baseClass baseObj; 
   tick_t startTime,endTime;
       rdtscll(startTime);
   baseObj.foo();
   rdtscll(endTime);
   std::cout<<"native foo() call takes "<< endTime-startTime <<" clock cycles"<<std::endl;
   rdtscll(startTime);
   baseObj.threadFoo();
       rdtscll(endTime);
       std::cout<<"Thread foo() call takes "<< endTime-startTime <<" clock cycles"<<std::endl;  
  }

You can compile it with g++ -lboost_thread-mt main.cpp and here is the sample output in my machine:

main startup
native foo() call takes 2187 clock cycles
Thread foo() call takes 29630434 clock cycles
  • 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-10T00:23:24+00:00Added an answer on June 10, 2026 at 12:23 am

    What you really want is a thread pool:

    #include "threadpool.hpp"
    
    int main()
    {
        boost::threadpool::pool threadpool(8);  // I have 4 cpu's
                                                // Might be overkill need to time
                                                // to get exact numbers but depends on
                                                // blocking and other factors.
    
        for(int loop = 0;loop < 100000; ++loop)
        {
            // schedule 100,000 small tasks to be run in the 8 threads in the pool
            threadpool.schedule(task(loop));
        }
    
        // Destructor of threadpool
        // will force the main thread to wait
        // for all tasks to complete before exiting
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started using boost::thread recently (WinXP, VS10, BoostPro) and found that mutex can be
I've been using Boost::regex and Boost::regex_search and found that when I run the regex
I found that HTMLOptionsCollection object inherits properties and methods from HTMLCollection. HTMLOptionsCollections->HTMLCollection->Object->null Is there
I found that in the cocos2d Best Practices there is a suggestion to use
The boost threading library has an abstraction for thread specific (local) storage . I
I'm using Boost 1.51 under OS X 10.7.4 and I've found that linking against
I'm having trouble building a little program that uses Boost.Test on my Mac with
Is there a way to limit the header files that Boost.Build recursively scans for
I am trying to compile a program using boost thread with the latest version.
I have found that boost::signals2 uses sort of a lazy deletion of connected slots,

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.