<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Using boost::threadpool with boost::future</title>
	<link>http://efiquest.org/2009-12-10/40/</link>
	<description>(mostly in programming and *nix administration)</description>
	<pubDate>Fri, 10 Sep 2010 15:45:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: pachanga</title>
		<link>http://efiquest.org/2009-12-10/40/#comment-641</link>
		<dc:creator>pachanga</dc:creator>
		<pubDate>Thu, 10 Dec 2009 06:59:24 +0000</pubDate>
		<guid>http://efiquest.org/2009-12-10/40/#comment-641</guid>
		<description>This should be very easy to achieve with a simple wrapper around the task. For example:

&lt;pre lang="cpp"&gt;
template&lt;typename Task, typename Callback
struct TaskWithNotification
{
  TaskWithNotification(Task t, Callback c)
    : task(t),
      callback(c)
  {}

  void operator()()
  {
     callback(task());
  }
};
&lt;/pre&gt;

...and the usage is straightforward:

&lt;pre lang="cpp"&gt;
submit_job(
   threadpool, 
   TaskWithNotification(
     boost::bind(LoadUserTask, userId), 
     boost::bind(OnUserLoad, _1))
);
&lt;/pre&gt;

In C++0x completion handler can be a lambda.</description>
		<content:encoded><![CDATA[<p>This should be very easy to achieve with a simple wrapper around the task. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> Task, <span style="color: #0000ff;">typename</span> Callback
<span style="color: #0000ff;">struct</span> TaskWithNotification
<span style="color: #008000;">&#123;</span>
  TaskWithNotification<span style="color: #008000;">&#40;</span>Task t, Callback c<span style="color: #008000;">&#41;</span>
    <span style="color: #008080;">:</span> task<span style="color: #008000;">&#40;</span>t<span style="color: #008000;">&#41;</span>,
      callback<span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">void</span> operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
     callback<span style="color: #008000;">&#40;</span>task<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>&#8230;and the usage is straightforward:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">submit_job<span style="color: #008000;">&#40;</span>
   threadpool, 
   TaskWithNotification<span style="color: #008000;">&#40;</span>
     boost<span style="color: #008080;">::</span><span style="color: #007788;">bind</span><span style="color: #008000;">&#40;</span>LoadUserTask, userId<span style="color: #008000;">&#41;</span>, 
     boost<span style="color: #008080;">::</span><span style="color: #007788;">bind</span><span style="color: #008000;">&#40;</span>OnUserLoad, _1<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>In C++0x completion handler can be a lambda.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Denis Bazhenov</title>
		<link>http://efiquest.org/2009-12-10/40/#comment-637</link>
		<dc:creator>Denis Bazhenov</dc:creator>
		<pubDate>Wed, 09 Dec 2009 23:45:25 +0000</pubDate>
		<guid>http://efiquest.org/2009-12-10/40/#comment-637</guid>
		<description>Conception of Futures very popular on Java Platform also. But there is one thing that I'm missing in Futures - asynchronous completition. Sometimes there is no need to wait for task to complete. All I need is to give task and completition function to thread pool. For example:

&lt;pre lang="java"&gt;
Callable task = new LoadUserTask(userId);
executor.submit(task, new CompletionHandler {
  public void onComplete(User user) {
    user.setLastLoginTime(now());
  }
});
&lt;/pre&gt;

Is there something similar in C++?</description>
		<content:encoded><![CDATA[<p>Conception of Futures very popular on Java Platform also. But there is one thing that I&#8217;m missing in Futures - asynchronous completition. Sometimes there is no need to wait for task to complete. All I need is to give task and completition function to thread pool. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Callable task <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LoadUserTask<span style="color: #009900;">&#40;</span>userId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
executor.<span style="color: #006633;">submit</span><span style="color: #009900;">&#40;</span>task, <span style="color: #000000; font-weight: bold;">new</span> CompletionHandler <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onComplete<span style="color: #009900;">&#40;</span>User user<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    user.<span style="color: #006633;">setLastLoginTime</span><span style="color: #009900;">&#40;</span>now<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Is there something similar in C++?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
