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

single-thread feature for removing ELF TLS dependency #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

EkardNT
Copy link

@EkardNT EkardNT commented Dec 11, 2019

Adds a new feature single-thread which when activated removes the #[thread_local] dependency. The catch is that the user must guarantee that futures will never be polled from more than one thread.

I intend to use this support to allow me to run futures on a STM32F103 board which only has a single core, so the only-one-thread limitation is not a problem. In general I expect this feature to only be used to target similar embedded systems.

Copy link
Member

@roblabla roblabla left a comment

Choose a reason for hiding this comment

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

Looking good!

Just a couple things:

  1. I'd like the name of the feature to be named "unsafe-single-thread". This is because using that feature in a multi-threaded environment will lead to memory unsafety, and I want to make sure the user is aware of that and properly reads the documentation.

  2. There's an important catch when it comes to embedded usage: Interrupts counts as a separate thread as well! So "running your code on a microcontroller that has only a single processor is an
    easy way of guaranteeing that the single-thread contract is upheld." is wrong, and I think should be specifically called out that interrupts are considered their own thread and shouldn't be using await.

rust-toolchain Show resolved Hide resolved
src/future.rs Outdated Show resolved Hide resolved
@EkardNT
Copy link
Author

EkardNT commented Dec 11, 2019

I added a warning about not polling futures from an interrupt routine. However, are interrupts actually a problem so long as they occur on the same core? I get that the TLS_CX variable wouldn't be automatically restored by the CPU itself when the interrupt returns, but the SetOnDrop logic seems like it would have the same effect.

Example timeline:

  1. Program polls a future, installs value A in TLS_CX.
  2. Interrupt occurs.
  3. Interrupt code polls a future, installs value B in TLS_CX. A is recorded in the SetOnDrop.
  4. Interrupt poll completes, value A is restored in TLS_CX.
  5. Interrupt completes.
  6. Program continues with polling future. It still sees the expected value A in TLS_CX.

Even interrupts within interrupts or chained interrupts would succeed due to to the SetOnDrop logic, right?

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.

2 participants