Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using the C++11 thread library (or Boost.Thread) then what you probably want is a <a href="http://en.cppreference.com/w/cpp/thread/future" rel="nofollow"><code>std::future</code></a>. They can be obtained in one of three ways:</p> <ol> <li>By passing a <a href="http://en.cppreference.com/w/cpp/thread/promise" rel="nofollow"><code>std::promise</code></a> to a thread and having it set the value.</li> <li>By using a <a href="http://en.cppreference.com/w/cpp/thread/packaged_task" rel="nofollow"><code>std::packaged_task</code></a>.</li> <li>By calling <a href="http://en.cppreference.com/w/cpp/thread/async" rel="nofollow"><code>std::async</code></a>.</li> </ol> <p>Here's an example using <code>std::async</code>:</p> <pre><code>some_return_type my_work_function( some_input_type const &amp; ); some_input_type inputs_to_slave_threads[] = { /* ... */ }; std::future&lt; some_return_type &gt; // launch the slaves, letting the OS decide whether to spawn new threads slave_0_future = std::async( my_work_function, std::ref( inputs_to_slave_threads[0] ) ), slave_1_future = std::async( my_work_function, std::ref( inputs_to_slave_threads[1] ) ), // ... slave_N_future = std::async( my_work_function, std::ref( inputs_to_slave_threads[N] ) ); some_return_type // block until results are ready result_of_slave_0 = slave_0_future.get(), result_of_slave_1 = slave_1_future.get(), // ... result_of_slave_N = slave_N_future.get(); process_results_of_slaves( result_of_slave_0, ..., result_of_slave_N ); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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