Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost.thread] function call and functor in thread creation: performance
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-01-21 23:53:45


AMDG

On 1/21/2011 5:55 PM, Boost lzw wrote:
> A new thread can be created using boost thread either from a function or a
> functor as the entry point of the new thread, as:
>
> void thread_function();
> boost::thread thrd(&function);
>
> class functor
> {
> public:
> inline void operator()();
> };
> functor f;
> boost::thread thrd(f);
>
> Is there a performance difference between these two?
>
> In an ordinary C++ program, can I claim that calling f() 1000 times gives
> better performance than calling thread_function() 1000 times, because the
> functor is hinted "inline" even the hint is igored by my compiler? Is f()
> the same as a function call in term of performance?
>

The cost if creating the thread almost
certainly swamps the function call overhead.
Even ignoring this, if the work the function
does is trivial enough that inlining matters,
then you probably shouldn't be spawning a thread
for it anyway.

In Christ,
Steven Watanabe


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