|
Boost Users : |
Subject: [Boost-users] Thread overhead
From: Alireza Haghdoost (haghdoost_at_[hidden])
Date: 2012-08-20 00:11:49
Hi
Is there anyway to reduce overhead of threadFoo() call in this simple program ?
class baseClass {
public:
void foo(){
boost::posix_time::milliseconds delay(143);
boost::this_thread::sleep(delay);
}
void threadFoo(){
threadObjOne = boost::thread(&baseClass::foo, this);
threadObjTwo = boost::thread(&baseClass::foo, this);
threadObjOne.join();
threadObjTwo.join();
}
private:
boost::thread threadObjOne;
boost::thread threadObjTwo;
};
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;
}
The output is :
main startup
native foo() call takes 368222398 clock cycles
Thread foo() call takes 372600905 clock cycles
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net