Boost C++ Libraries: Ticket #2741: proposal to manage portable and non portablethread attributes https://svn.boost.org/trac10/ticket/2741 <p> Boost.thread has already a non portable interface to get the thread handle </p> <div class="wiki-code"><div class="code"><pre><span class="k">class</span> <span class="nc">thread</span> <span class="p">{</span> <span class="k">public</span><span class="o">:</span> <span class="p">...</span> <span class="k">typedef</span> <span class="n">np_native_handle_type</span> <span class="n">native_handle_type</span><span class="p">;</span> <span class="n">native_handle_type</span> <span class="nf">native_handle</span><span class="p">();</span> <span class="p">...</span> <span class="p">};</span> </pre></div></div><p> Boost.Thread do not allows to pass thread attributes on the thread constructor. I suppose that this is due to portable issues. Could we identify which attributes are portable and which one not? </p> <p> The portable attributes (as stack size, ...) can be grouped on a thread_attributes class. </p> <p> In order to be able to pass whatever attribute to the thread constructor we can add the setting of non portable attributes to this thread_attributes class, and making the thread constructor take a thread_attributes in addition to the existing parameters. </p> <div class="wiki-code"><div class="code"><pre><span class="k">class</span> <span class="nc">thread</span> <span class="p">{</span> <span class="k">public</span><span class="o">:</span> <span class="k">class</span> <span class="nc">thread_attributes</span> <span class="p">{</span> <span class="c1">// portable attributes</span> <span class="k">public</span><span class="o">:</span> <span class="k">typedef</span> <span class="n">np_native_handle_type</span> <span class="n">native_handle_type</span><span class="p">;</span> <span class="n">native_handle_type</span> <span class="nf">native_handle</span><span class="p">();</span> <span class="c1">// set/get of attributes</span> <span class="c1">// ..</span> <span class="cp">#if defined(BOOST_THREAD_PLATFORM_WIN32)</span> <span class="c1">// ... window version</span> <span class="cp">#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)</span> <span class="k">private</span><span class="o">:</span> <span class="n">pthread_attr_t</span> <span class="n">native_attributes</span><span class="p">;</span> <span class="k">public</span><span class="o">:</span> <span class="n">thread_attributes</span><span class="p">()</span> <span class="p">{</span> <span class="n">pthread_attr_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">native_attributes</span><span class="p">);</span> <span class="p">}</span> <span class="o">~</span><span class="n">thread_attributes</span><span class="p">()</span> <span class="p">{</span> <span class="n">pthread_attr_destroy</span><span class="p">(</span><span class="o">&amp;</span><span class="n">native_attributes</span><span class="p">);</span> <span class="p">}</span> <span class="c1">// ... other</span> <span class="cp">#else</span> <span class="cp">#error &quot;Boost threads unavailable on this platform&quot;</span> <span class="cp">#endif</span> <span class="p">};</span> <span class="kr">thread</span><span class="p">(</span><span class="k">const</span> <span class="n">thread_attributes</span><span class="o">&amp;</span><span class="n">p</span><span class="p">,</span> <span class="n">F</span> <span class="n">f</span><span class="p">,</span><span class="n">A1</span> <span class="n">a1</span><span class="p">);</span> <span class="p">...</span> <span class="p">};</span> </pre></div></div><p> The portable application needing some specific configuration can construct portable threads using the following schema </p> <div class="wiki-code"><div class="code"><pre> <span class="kr">thread</span><span class="o">::</span><span class="n">thread_attributes</span> <span class="n">attr</span><span class="p">;</span> <span class="c1">// set portable attributes</span> <span class="c1">// ...</span> <span class="n">attr</span><span class="p">.</span><span class="n">set_stack_size</span><span class="p">(</span><span class="mi">1000000</span><span class="p">)</span> <span class="cp">#if defined(BOOST_THREAD_PLATFORM_WIN32)</span> <span class="c1">// ... window version</span> <span class="cp">#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)</span> <span class="c1">// ... pthread version</span> <span class="n">pthread_attr_setschedpolicy</span><span class="p">(</span><span class="n">attr</span><span class="p">.</span><span class="n">get_native_handle</span><span class="p">(),</span> <span class="n">SCHED_RR</span><span class="p">);</span> <span class="cp">#else</span> <span class="cp">#error &quot;Boost threads unavailable on this platform&quot;</span> <span class="cp">#endif</span> <span class="kr">thread</span> <span class="nf">th</span><span class="p">(</span><span class="n">attr</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span><span class="n">ctx</span><span class="p">);</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2741 Trac 1.4.3 Alvaro Sat, 18 Apr 2009 00:05:51 GMT <link>https://svn.boost.org/trac10/ticket/2741#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2741#comment:1</guid> <description> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 30 May 2009 07:59:26 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2741 https://svn.boost.org/trac10/ticket/2741 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_ticket_2741.cpp</span> </li> </ul> Ticket viboes Sat, 30 May 2009 08:03:40 GMT attachment set https://svn.boost.org/trac10/ticket/2741 https://svn.boost.org/trac10/ticket/2741 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">2741_b.patch</span> </li> </ul> <p> patch src </p> Ticket viboes Sat, 30 May 2009 08:04:55 GMT attachment set https://svn.boost.org/trac10/ticket/2741 https://svn.boost.org/trac10/ticket/2741 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">2741_a.patch</span> </li> </ul> <p> patch headers </p> Ticket viboes Sat, 30 May 2009 08:08:10 GMT <link>https://svn.boost.org/trac10/ticket/2741#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2741#comment:2</guid> <description> <p> The attached files contains the test of the new feature and a two patch implementing it: one for the headers and one for the sources. </p> </description> <category>Ticket</category> </item> <item> <author>tim@…</author> <pubDate>Thu, 01 Dec 2011 10:56:00 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/2741#comment:3 https://svn.boost.org/trac10/ticket/2741#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">tim@…</span> added </li> </ul> Ticket viboes Fri, 02 Dec 2011 05:04:28 GMT <link>https://svn.boost.org/trac10/ticket/2741#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2741#comment:4</guid> <description> <p> See also <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5956" title="#5956: Feature Requests: Add optional stack_size argument to thread::start_thread() (closed: duplicate)">#5956</a> Add optional stack_size argument to thread::start_thread() </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 02 Dec 2011 05:13:10 GMT</pubDate> <title>cc, milestone changed https://svn.boost.org/trac10/ticket/2741#comment:5 https://svn.boost.org/trac10/ticket/2741#comment:5 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.39.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> See also <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2880" title="#2880: Feature Requests: Request for Thread scheduler support for boost .. (closed: duplicate)">#2880</a> Request for Thread scheduler support for boost .. </p> Ticket viboes Fri, 02 Dec 2011 05:13:58 GMT <link>https://svn.boost.org/trac10/ticket/2741#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2741#comment:6</guid> <description> <p> See also <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3696" title="#3696: Feature Requests: Boost Thread library lacks any way to set priority of threads (closed: duplicate)">#3696</a> Boost Thread library lacks any way to set priority of threads </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 31 Dec 2011 09:35:59 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/2741#comment:7 https://svn.boost.org/trac10/ticket/2741#comment:7 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sat, 07 Jan 2012 23:01:36 GMT milestone changed https://svn.boost.org/trac10/ticket/2741#comment:8 https://svn.boost.org/trac10/ticket/2741#comment:8 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.49.0</span> </li> </ul> Ticket viboes Tue, 17 Jan 2012 06:33:58 GMT <link>https://svn.boost.org/trac10/ticket/2741#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2741#comment:9</guid> <description> <p> Committed in trunk at revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/76543" title=" * [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to ...">[76543]</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 28 May 2012 15:11:02 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/2741#comment:10 https://svn.boost.org/trac10/ticket/2741#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.49.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Committed in release branch at <a class="changeset" href="https://svn.boost.org/trac10/changeset/78543" title="Merged boost.thread from trunk">[78543]</a> </p> Ticket