Thread Wrapper Example

// g++ -pthread threadwrapper.cpp -o threadwrapper

In this program, how would you make sure that MESSAGE is printed when running the program by only changing the constructor and destructor of the class?

/*
    In this program, how would you make sure that MESSAGE is printed when running the program?
*/
#include <iostream>
#include <thread>
#include <string>
#include <chrono>  // Added for sleep_for functionality

std::string MESSAGE = "THIS IS TO BE PRINT";

class ThreadWrapper {
public:
    std::thread localThread;
    
    ThreadWrapper(std::thread t) {
        localThread = std::move(t); // move not copy the thread
    }
    
    ~ThreadWrapper() {
    }
};

void threadThat() {
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout << MESSAGE << std::endl;
}

void CallThreadWork() {
    std::this_thread::sleep_for(std::chrono::seconds(1));
    ThreadWrapper thread{std::thread(threadThat)};
    
}

int main() {
    CallThreadWork();
    std::cout << "Ok yeah!";
    return 0;
}