Skip to content

Instantly share code, notes, and snippets.

@khoa-io
Last active September 26, 2022 08:42
Show Gist options
  • Save khoa-io/068782c5edaba0a08ae9958d540b8f12 to your computer and use it in GitHub Desktop.
Save khoa-io/068782c5edaba0a08ae9958d540b8f12 to your computer and use it in GitHub Desktop.
Hello Multithreading World (C++ Thread)
#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