Flush stdout after PUTS
and OUT
traps
#39
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #24
Always flush stdout after
PUTS
orOUT
trap call.This could hypothetically affect performance for programs with a large number of consecutive
OUT
operations (though I don't think this matters).A way to solve this would be to flush stdout before
IN
trap reads stdin. Since this is the only blocking instruction, and stdout is automatically flushed when the process unwinds (triggered byHALT
or a panic), this should work for most cases (std::process::abort
will not cause unwinding, but if this program has to abort, it has bigger problems anyway). Regardless, with this alternative method, the problem will still occur if a large (or infinite) loop is executed before stdout can be flushed.