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

I2C: document concurrent access #216

Open
ysoldak opened this issue Oct 13, 2021 · 1 comment
Open

I2C: document concurrent access #216

ysoldak opened this issue Oct 13, 2021 · 1 comment

Comments

@ysoldak
Copy link
Contributor

ysoldak commented Oct 13, 2021

Use of I2C in TinyGo is not "thread-safe".
HAL would not use mutex to serialise concurrent access. Synchronisation when needed, must be done in application code.

This is contra, for example, to Linux I2C driver that uses internal mutex to enable easy concurrent usage.

Arguments against implementing such internal mutex in TinyGo (from slack):

  • it is usually not necessary [in embedded systems] and thus introduces overhead
  • easy to add but impossible to remove (for backwards compatibility reasons)

Page: https://tinygo.org/docs/concepts/peripherals/i2c/

@aykevl
Copy link
Member

aykevl commented Oct 14, 2021

Note that in the case of Linux, the kernel has to synchronize access to the I2C bus for safe operation. I'm pretty sure the hardware will misbehave when access isn't synchronized which would be unacceptable when done from an unprivileged process. So I think it's also a security feature, not just a convenience feature. This security argument doesn't apply to TinyGo.

(This is a bit of speculation though...)

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

No branches or pull requests

2 participants