#include <iostream>
#include <iomanip>
#include <thread>

using namespace std;

void print()
{
    cout<<"Hello!!";
}

void print2()
{
    for(int i = 0; i < 8; ++i)
    {
        cout << "meanwhile...\n";
        this_thread::sleep_for(chrono::milliseconds(200));
    }
}

thread test()
{
    this_thread::sleep_for(chrono::milliseconds(200));
    return thread([&]() {
        this_thread::sleep_for(chrono::milliseconds(400));
        cout << "Connection is successful! Wait...\n";
        this_thread::sleep_for(chrono::milliseconds(400));
        cout << "Setting up the environment!\n";
        this_thread::sleep_for(chrono::milliseconds(400));
        cout <<"All is done!\n";});
}

int main(int argc, char * argv[])
{
    auto t = test();
    print2();
    t.join();
    print();
}
