Cleaning Up Function on exit() C++

Viewed 204

Suppose I have a future object to run a process, and then in my main function I check if the process is timed out, in which case I want to end the program.

Consider the following template code:

//(include relevant libraries)
int main() {
    std::future<int> future = std::async(std::launch::async, []() {
        int result = uncertainFunctionCall();
        return result;
    });
    std::future_status status = future.wait_for(std::chrono::milliseconds(50));
    if (status == std::future_status::timeout) {
       std::cout << "Timeout" << std::endl;
       exit();
    }
    try {
        std::cout << future.get() << std::endl;
        std::cout << "Success" << std::endl;
    }
    catch(...) {
        std::cout << "Exception Occurred" << std::endl;
        exit(); 
    }
    return 0; 
}

My question is, should there circumstances under which I need to do some cleaning up before calling the exit() function? For my use case, I only care about getting the value, but I don't want uncertainFunctionCall() to affect future executions of this program.

0 Answers
Related