-
Notifications
You must be signed in to change notification settings - Fork 3
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
Concurrency bug when calling an SDK function with multiple thread #398
Comments
@josiah-tesfu include your test code please for both shared sdk and protected. |
@sj608 this is a reproducible issue now. @josiah-tesfu has test codes (which should be added to this ticket soon) that can produce the error consistently. |
regarding this test, I just want to add that I think the reason that it is passing is not because the sdk is non-shared but because sdk init is slow the threads do not have a good chance to overlap |
@sjpark608 to make all tests fail just increase number of threads from 5 to 30 here:
|
This comment is to sum up our brief discussion about thread safety of SDK
reference_1, reference_2, spidev.h source, reference_3, i2c-dev.h source |
When calling an SDK function with multiple threads which use a shared SDK instance, one of the following exceptions occurs:
This specific stack trace arises from calling
set_rtd
in the ADC Service with multiple threads using a shared SDK instance, but other functions called also cause the same exceptions to be raised. The bug seems to arise when multiple SDK instances use a shared hardware resource -- in this case I2C and SPI devices.When testing for this exception, I found that when the threads each have their own instance of the SDK the tests pass. The tests fail if the threads share an SDK instance, with the rate of failure increasing with more threads. Additionally, the tests pass if the threads share an SDK instance but the SDK function call is protected with a lock.
Test code to reproduce the issue:
Shared SDK instance (subset of the tests fail):
Shared SDK instance with lock (all tests pass):
Non-shared instances (all tests pass):
The text was updated successfully, but these errors were encountered: