Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The overhead of stringifying <code>thread::id</code> (only to compute the string hash afterward) is, as you almost said yourself, astronomical compared to any performance benefits a <code>tr1::unordered_map</code> might confer vis-a-vis <code>std::map</code>. So the short answer would be: <strong>stick with std::map&lt; thread::id, ... ></strong></p> <p>If you <em>absolutely</em> must use unordered containers, <strong>try to use<code>native_handle_type</code></strong> instead of <code>thread::id</code> if possible, i.e. prefer <code>tr1::unordered_map&lt; thread::native_handle_type, ... &gt;</code>, invoking <code>thread::native_handle()</code> instead of <code>thread::get_id()</code> when <code>insert</code>ing and <code>find</code>ing.</p> <p><strong>DO NOT attempt anything like the following</strong>:</p> <pre><code>struct boost_thread_id_hash { // one and only member of boost::thread::id is boost::thread::id::thread_data // of type boost::detail::thread_data_ptr; // boost::thread::id::operator==(const id&amp;) compares boost::thread::id::thread_data's size_t operator()(boost::thread::id const&amp; id) const { const boost::detail::thread_data_ptr* pptdp = \ reinterpret_cast&lt; boost::detail::thread_data_ptr* &gt;(&amp;id); return h(pptdp-&gt;get()); } }; </code></pre> <p>It could work, but is extremely brittle and an almost guaranteed timebomb. It assumes intimate knowledge of the inner workings of the <code>thread::id</code> implementation. It will get you cursed at by other developers. Don't do it if maintainability is of any concern! Even patching <code>boost/thread/detail/thread.hpp</code> to add <code>size_t hash_value(const id&amp; tid)</code> as a friend of <code>thread::id</code> is "better". :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload