I tend to think the job that a thread does is non-trivial. Does this mean that I should never try to inline the function call operator? Does anyone know the performance difference between creating a new boost thread via ordinary function vs. doing that via a functor?

Thanks

On Fri, Jan 21, 2011 at 11:53 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users