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?<br>
<br>Thanks<br><br><div class="gmail_quote">On Fri, Jan 21, 2011 at 11:53 PM, Steven Watanabe <span dir="ltr">&lt;<a href="mailto:watanabesj@gmail.com">watanabesj@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
AMDG<div><div></div><div class="h5"><br>
<br>
On 1/21/2011 5:55 PM, Boost lzw wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
A new thread can be created using boost thread either from a function or a<br>
functor as the entry point of the new thread, as:<br>
<br>
void thread_function();<br>
boost::thread thrd(&amp;function);<br>
<br>
class functor<br>
{<br>
public:<br>
 � � � � �inline void operator()();<br>
};<br>
functor f;<br>
boost::thread thrd(f);<br>
<br>
Is there a performance difference between these two?<br>
<br>
In an ordinary C++ program, can I claim that calling f() 1000 times gives<br>
better performance than calling thread_function() 1000 times, because the<br>
functor is hinted &quot;inline&quot; even the hint is igored by my compiler? Is f()<br>
the same as a function call in term of performance?<br>
<br>
</blockquote>
<br></div></div>
The cost if creating the thread almost<br>
certainly swamps the function call overhead.<br>
Even ignoring this, if the work the function<br>
does is trivial enough that inlining matters,<br>
then you probably shouldn&#39;t be spawning a thread<br>
for it anyway.<br>
<br>
In Christ,<br><font color="#888888">
Steven Watanabe<br>
_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org" target="_blank">Boost-users@lists.boost.org</a><br>
<a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br>
</font></blockquote></div><br>