Last active
September 26, 2022 08:42
-
-
Save khoa-io/068782c5edaba0a08ae9958d540b8f12 to your computer and use it in GitHub Desktop.
Hello Multithreading World (C++ Thread)
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 <string> | |
#include <system_error> | |
#include <thread> | |
class BackgroundTask { | |
public: | |
void operator()() const { | |
std::cout << "Hello Multithreading World" << std::endl; | |
} | |
}; | |
int main() { | |
try { | |
BackgroundTask task; | |
std::thread myThread(task); | |
myThread.join(); | |
} catch (std::system_error const &error) { | |
std::cout << error.what() << std::endl; | |
return -1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment