A volatile flag used for a producer/consumer handoff

producer and consumer run concurrently on separate threads, with ready marked volatile instead of std::atomic<bool>. Does volatile make this safe, and what does the program do?

main.cpp
volatile bool ready = false;
int data = 0;

void producer() {
    data = 42;
    ready = true;
}

void consumer() {
    while (!ready) {}
    std::cout << data << std::endl;
}

12 of 51 in Concurrency