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

reading registers is not thread safe #21

Open
penguinland opened this issue Feb 1, 2024 · 0 comments
Open

reading registers is not thread safe #21

penguinland opened this issue Feb 1, 2024 · 0 comments

Comments

@penguinland
Copy link

penguinland commented Feb 1, 2024

I suspect this repo is no longer maintained (last update was 5 years ago) so this won't get fixed, but I'll report this just in case. Methods like ReadRegS16BE sound like they ought to be atomic, but they're not (e.g., https://github.com/d2r2/go-i2c/blob/master/i2c.go#L134-L139 shows that we write to the I2C device, and then read from it afterwards). If I try reading two different registers in two different goroutines, there are race conditions: I can get bad responses when the first goroutine writes the register to interact with, then the second one writes the register to interact with, then the first one reads the contents of the register.

I don't know if it's possible to fix this with the current implementation (reading/writing to the pseudofile in /dev, rather than using ioctl). The simpler way to address this might be to put a warning in the readme saying this library is not thread safe.

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

1 participant