Async를 사용하는 방법
#include <iostream>
#include <future>
using namespace std::chrono_literals;
int fn() {
std::this_thread::sleep_for(1s);
std::cout << "async fn is called" << std::endl;
return 42;
}
int main()
{
//task기반의 비동기 처리
std::future<int> fut = std::async(std::launch::async, fn);
int num = fut.get();
std::cout << "Hello World : " << num << std::endl;
}
결과값
async fn is called
Hello World : 42
댓글