Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Last active February 18, 2020 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/a6f769a2d65cb137ade215c624d1deb9 to your computer and use it in GitHub Desktop.
Save jitpaul/a6f769a2d65cb137ade215c624d1deb9 to your computer and use it in GitHub Desktop.
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