-
-
Save jitpaul/eb7182c05d4040a6b0e31bfbf8c158f9 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(){ | |
// Execute the task in the same thread. | |
std::packaged_task<void()> task1(someTask); | |
auto f1 = task1.get_future(); | |
task(); | |
int ret1 = f1.get(); | |
// Execute the task in a separate thread. | |
std::packaged_task<void()> task2(someTask); | |
auto f2 = task2.get_future(); | |
std::thread(task); | |
int ret2 = f2.get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment