Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush stdout after PUTS and OUT traps #39

Merged
merged 1 commit into from
Sep 21, 2024
Merged

Conversation

dxrcy
Copy link
Contributor

@dxrcy dxrcy commented Sep 21, 2024

Fixes #24
Always flush stdout after PUTS or OUT 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 by HALT 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.

Copy link
Owner

@rozukke rozukke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good, don't think performance is too big of a deal here

@rozukke rozukke merged commit 6fc5c30 into rozukke:main Sep 21, 2024
3 checks passed
@dxrcy dxrcy deleted the flush-stdout branch September 21, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

puts is not flushed in some cases
2 participants