Re: Is PCA9685 code thread safe?
by adafruit_support_bill on Thu Feb 18, 2021 6:59 am
If you think about it, it is not possible to make libraries for i2c devices (or serial devices in general) thread-safe for the general case.
Assuming that you could make bus transactions atomic at the i2c level, what constitutes an atomic operation at the device level may not be limited to a single bus transaction.
Further assuming that you could get all library authors to play be the same synchronization rules, you would still have the issue that what constitutes an atomic operation at the application level may not be limited to what is atomic at the device level.
If you want to have multi-threaded access to bus devices, you will need to synchronize them at the application level.