Skip to content

Instantly share code, notes, and snippets.

@jitpaul

jitpaul/async.cpp Secret

Last active Feb 18, 2020
Embed
What would you like to do?
Multithreading
#include <iostream>
#include <future>
#include <thread>
int someTask(){
std::cout << "Some task\n";
}
int main(){
// The task may or may not get executed in a separate thread.
auto f1 = std::async(someTask);
int ret1 = f1.get();
// The task is guaranteed to execute in a separate thread.
auto f2 = std::async(std::launch::async, someTask);
int ret2 = f2.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment