InterviewSolution
| 1. |
Can You Create A C++11 Thread With A Lambda Closure That Takes A Bunch Of Arguments? |
|
Answer» Yes – just like the previous case, you can pass the arguments needed by the lambda closure to the thread constructor. auto LaunchTorpedoFunc = [](INT numCities, string torpedoType) -> void { COUT << "Firing torpedo " << torpedoType << " at" << numCities << " cities." << ENDL; }; thread T1(LaunchTorpedoFunc, 7, "Barracuda"); t1.join(); Yes – just like the previous case, you can pass the arguments needed by the lambda closure to the thread constructor. auto LaunchTorpedoFunc = [](int numCities, string torpedoType) -> void { cout << "Firing torpedo " << torpedoType << " at" << numCities << " cities." << endl; }; thread t1(LaunchTorpedoFunc, 7, "Barracuda"); t1.join(); |
|