An example that demonstrates how to create and manage threads.
cppCopy code#include <iostream>
#include <thread>
void printMessage() {
std::cout << "Hello from thread!" << std::endl;
}
int main() {
std::thread t(printMessage);
t.join(); // Wait for the thread to finish
return 0;
}
Leave a Reply