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

Multithreading smooth-out #7

Merged
merged 6 commits into from
Jun 4, 2018
Merged

Multithreading smooth-out #7

merged 6 commits into from
Jun 4, 2018

Conversation

Xasin
Copy link
Collaborator

@Xasin Xasin commented Jun 4, 2018

Hey there!
For my smart home project, as I expanded it, I began to notice a few odd behaviours of my I2C-connected components.

Upon analysis with my Salea, I noticed two things:

  • There was an unnecessary write in front of read operations. SLA+W was sent, but no data. (No data was expected)
  • Communications seemed to get mixed up with each other.

The former point was a simple manner of rewriting the read() code to not always execute the write function.
The second point was a lack of synchronisation between multiple threads, allowing different Threads to simultaneously write to @device, thusly confusing what data and address were sent where.

The mutex I added makes sure that only one Thread can ever access the @device between setting address, writing and reading. It can additionally be accessed and locked manually, to perform multiple consecutive read or write operations to single or multiple devices.


This change is Reviewable

Xasin and others added 6 commits June 4, 2018 11:47
Update from fork master
It does not synchronize between different Ruby instances,
but at least will smooth out communication between different
Ruby threads of the same instance.
@Xasin
Copy link
Collaborator Author

Xasin commented Jun 4, 2018

Review status: all files reviewed at latest revision, all discussions resolved.


i2c.gemspec, line 3 at r2 (raw file):

Gem::Specification.new do |s|
  s.name        = 'i2c'
  s.version     = '0.4.2-dev'

Change to the official version before publishing


Comments from Reviewable

@andec andec merged commit bef41cf into andec:master Jun 4, 2018
@andec
Copy link
Owner

andec commented Jun 4, 2018

Thank you!

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