Skip to content

Instantly share code, notes, and snippets.

@tiandiao123
Created December 21, 2022 21:09
Show Gist options
  • Select an option

  • Save tiandiao123/ddefadeabc37085d195cdc2f3cc58ab6 to your computer and use it in GitHub Desktop.

Select an option

Save tiandiao123/ddefadeabc37085d195cdc2f3cc58ab6 to your computer and use it in GitHub Desktop.
#include <future>
#include <iostream>
using namespace std;
int factorial(int N){
if(N == 1){
return 1;
}
return N * factorial(N-1);
}
int main(){
std::future<int> fu = std::async(factorial, 4);
std::future<int> fu2 = std::async(factorial, 6);
int x = fu.get();
int x2 = fu2.get();
cout << "x: " << x << endl;
cout <<"x2: " << x2 << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment