-
-
Save jitpaul/a6f769a2d65cb137ade215c624d1deb9 to your computer and use it in GitHub Desktop.
Multithreading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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