Skip to content

Docs: Detail issue with hard ISRs and globals. #10620

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

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/reference/isr_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,17 @@ is partially updated. When the ISR tries to read the object, a crash results. Be
on rare, random occasions they can be hard to diagnose. There are ways to circumvent this issue, described in
:ref:`Critical Sections <Critical>` below.

It is important to be clear about what constitutes the modification of an object. An alteration to a built-in type
such as a dictionary is problematic. Altering the contents of an array or bytearray is not. This is because bytes
or words are written as a single machine code instruction which is not interruptible: in the parlance of real time
programming the write is atomic. A user defined object might instantiate an integer, array or bytearray. It is valid
for both the main loop and the ISR to alter the contents of these.
It is important to be clear about what constitutes the modification of an object. Altering the contents of an array
or bytearray is safe. This is because bytes or words are written as a single machine code instruction which is not
interruptible: in the parlance of real time programming the write is atomic. The same is true of updating a
dictionary item because items are machine words, being integers or pointers to objects. A user defined object might
instantiate an array or bytearray. It is valid for both the main loop and the ISR to alter the contents of these.

The hazard arises when the structure of an object is altered, notably in the case of dictionaries. Adding or deleting
keys can trigger a rehash. If a hard ISR runs while a rehash is in progress and attempts to access an item, a crash
may occur. Internally globals are implemented as a dictionary. Consequently the main program should create all
necessary globals before starting a process that generates hard interrupts. Application code should also avoid
deleting globals.

MicroPython supports integers of arbitrary precision. Values between 2**30 -1 and -2**30 will be stored in
a single machine word. Larger values are stored as Python objects. Consequently changes to long integers cannot
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy