Question: what causes stdout to flush after `main`

Currently, when I write this:

fn main() {
    // No newline
    print!("Hello, World");
    std::thread::sleep(1);
}

I see Hello World printed to stdout after the sleep, when the program finishes. This would imply that there is some mechanism by which the BufWriter is flushed (presumably it's dropped). Does anyone know what that mechanism is or where it happens? Normally, globals aren't dropped at all, even after the program returns (as they are in C++). I wasn't seeing anything obvious in stdio.rs that would cause this to happen in the stdout cast.

1 Like

Found by looking at

10 Likes

Excellent, thank you very much!