/*
std::async is a function that is part of the C++11 Standard Template Library (STL)
and allows for the creation of asynchronous operations. Asynchronous operations 
allow a program to perform multiple tasks simultaneously without waiting for one
task to complete before starting another.

std::async allows you to launch a function or a callable object (such as a lambda 
function) in a separate thread and obtain a handle to the result of that function. 
The function is executed in a separate thread and the program can continue to 
execute other tasks while the function runs.

Here is an example of using std::async to perform a long-running task in a separate
thread:*/


#include <iostream>
#include <thread>
#include <chrono>

void long_running_task() {
    std::cout << "Performing long-running task..." << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(5));
    std::cout << "Task complete." << std::endl;
}

int main() {
    std::cout << "Starting long-running task..." << std::endl;
    std::thread t(long_running_task); 
    std::cout << "Doing other work while the task runs..." << std::endl;
    // ...
    t.join(); 
    std::cout << "Retrieving result of long-running task..." << std::endl;
    std::cout << "Result of long-running task: " << std::endl;
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: