Started learning c++ threads. I have a problem but not sure if my solution would work. I need an application that create threads but run their functions on demand.
Lets say I create 4 threads from the main thread (main function).
Take this minimal example.
int main (){
int numThreads;
cin >> numThreads;
for (int i = 0; i < numThreads; i++) {
threadList[i] = std::thread(SomeClass);
}
while (true) {
int i;
cout << "Enter thread to execute from";
cin >> i;
cout << "Execute function of specific thread ";
someresponse = threadList[i].executeSomeClassFunction(); // execute specific thread function
cout << "Got some Response " << someresponse;
}
return 0;
}
Is it possible to implement something like this? The question I have is how I let the thread know what to execute.