Note that there are some explanatory texts on larger screens.

plurals
  1. POMultithreading using the boost library
    primarykey
    data
    text
    <p>Wish to simultaneously call a function multiple times. I wish to use threads to call a function which will utilize the machines capability to the fullest. This is a 8 core machine, and my requirement is to use the machine cpu from 10% to 100% or more. </p> <p>My requirement is to use the boost class. Is there any way I can accomplish this using the boost thread or threadpool library? Or some other way to do it?</p> <p>Also, if I have to call multiple functions with different parameters each time (with separate threads), what is the best way to do this? [using boost or not using boost] and how?</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; #include &lt;boost/thread/mutex.hpp&gt; #include &lt;boost/bind.hpp&gt; using namespace std; using boost::mutex; using boost::thread; int threadedAPI1( ); int threadedAPI2( ); int threadedAPI3( ); int threadedAPI4( ); int threadedAPI1( ) { cout &lt;&lt; "Thread0" &lt;&lt; endl; } int threadedAPI2( ) { cout &lt;&lt; "Thread1" &lt;&lt; endl; } int threadedAPI3( ) { cout &lt;&lt; "Thread2" &lt;&lt; endl; } int threadedAPI4( ) { cout &lt;&lt; "Thread3" &lt;&lt; endl; } int main(int argc, char* argv[]) { boost::threadpool::thread_pool&lt;&gt; threads(4); // start a new thread that calls the "threadLockedAPI" function threads.schedule(boost::bind(&amp;threadedAPI1,0)); threads.schedule(boost::bind(&amp;threadedAPI2,1)); threads.schedule(boost::bind(&amp;threadedAPI3,2)); threads.schedule(boost::bind(&amp;threadedAPI4,3)); // wait for the thread to finish threads.wait(); return 0; } </code></pre> <p>The above is not working and I am not sure why? :-(</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.
 

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