-
Notifications
You must be signed in to change notification settings - Fork 114
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
doc: add a tips and tricks section to the interrupt docs #378
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's stronger than this.
This is always the case. An interrupt always runs instead of regular code, and unless you use very weird hacks you can't continue normal code. (This is true for all architectures I've looked at: Cortex-M, AVR, Xtensa, RISC-V). In fact, the runtime now checks for these things and if it is inside an interrupt handler when any of these things occur (blocking operations, memory allocations) it will simply panic.
The reason memory allocations are not allowed is a bit more subtle: if an interrupt happens while the GC is running, it will mess with the internal state of the heap. (I've looked for possible ways to fix this but couldn't find anything that was acceptable for TinyGo).
I'd rather word this as something like "never use these things".
That falls under the general category of "too big for an interrupt". LEDs are a way to indicate things, and on some chips
println
will also work - but not on all (it will usually work when using UART, but USB-CDC is generally too complex to use inside an interrupt handler).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I ALWAYS avoid interrupts. Inconditionally. Unless you are writing real-time critical code down to the nanosecond, interrupts are a needless source of breakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Now realizing this has been merged by no one other than yours truly 🤦)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interrupts can also be useful to avoid polling and conserve battery life :)
But yeah, most users should not use interrupts. Instead, all that functionality should be hidden inside packages like the machine package.