I want to call a function with different value of arg many times. To make the execution faster I want to call the function without considering its implementation.
Inside a loop i pass the arg to the function and call it now my program should not wait for the function to execute and loop again, instead it should not consider that the function has not completed for the first loop it should go ahead and call the function again and again till the loop ends.
how to use fork and threads to do this , which one will be faster and a skeleton of code will help ?
Lets say my function is void foo(arg1,arg2)
You want an asynchronous implementation of the proactor pattern.
Here’s an example, using
boost::asioandboost::thread:The benefit here, is you can scale easily by calling
boost::asio::io_service::runfrom a pool of threads if necessary.