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.

2 Likes

Found by looking at

11 Likes

Excellent, thank you very much!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.