Skip to content

Wait for other thread to unlock when not able to lock #39

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 2 commits into from
Jul 27, 2022
Merged

Wait for other thread to unlock when not able to lock #39

merged 2 commits into from
Jul 27, 2022

Conversation

GwnDaan
Copy link
Contributor

@GwnDaan GwnDaan commented Jul 25, 2022

This request adds a sleep call of 0 seconds in the try_lock function. This resolves an issue where the current thread is constantly trying to lock the i2c bus, without giving another thread the 'opportunity' to complete it's operation and unlock the i2c bus.

This sleep call drastically improves performance on my pi zero board:
image
^ without the sleep call

image
^ using the sleep call

I'm not sure if this is the right way of 'unblocking' the i2c bus for other threads, but it's for sure 1000x better than before for me. Therefore I feel like it's worth sharing with others.

@GwnDaan
Copy link
Contributor Author

GwnDaan commented Jul 25, 2022

Note that this issue only occurs when using multiple threads with all of them constantly (without sleeping) trying to read values from different i2c busses over the multiplexer.

@tekktrik tekktrik requested a review from a team July 25, 2022 15:04
@tekktrik
Copy link
Member

Hm, @makermelissa and @tannewt this is interesting. This would imply that adafruit_bus_device should change as well.

@tannewt
Copy link
Member

tannewt commented Jul 25, 2022

Ya, interesting. This is lightweight enough that I'd be ok with the change here and in bus device. This doesn't mean our drivers are threadsafe though. They are tested on micros without threads generally.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Thanks!

@tekktrik tekktrik merged commit 1ad9f4d into adafruit:main Jul 27, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 27, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_TCA9548A to 0.6.0 from 0.5.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_TCA9548A#39 from GwnDaan/patch-1
  > Changed .env to .venv in README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_BusDevice to 5.2.0 from 5.1.10:
  > Merge pull request adafruit/Adafruit_CircuitPython_BusDevice#91 from tekktrik/dev/use-sleep
  > Changed .env to .venv in README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_SI1145
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.

3 participants