This sort of problem is best solved using std::async
and std::future
, which can use threads or not, depending on how you use them.
int main() {
std::cout << "Please enter an number" << std::endl;
int x;
std::cin >> x;
auto f_future = std::async(std::launch::async, f, x);
auto g_future = std::async(std::launch::async, g, x);
//will block until f's thread concludes, or until both threads conclude, depending on how f resolves
auto result = f_future.get() || g_future.get();
std::cout << /*...*/ << std::endl;
}
3
solved Parallel computing using threads in C++ [closed]