-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Request: Add option to disable non-lock-free atomics #1022
Comments
I'll take a look at that. |
Any macro to disable non-lock-free atomics will not work for
|
There was a property added to |
I checked the STL from gcc and MSVC: https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gcc/_005f_005fatomic-Builtins.html
Is there any reason that etl don't use built-ins for large data types? Can we just use those built-ins? So the user can be notified by a linker error and no unexpected behavior will happen. |
I'm adding a |
Do you mean this? |
Yes |
This somehow relates to my previous feature request: #880 |
Creating a generic, non-OS, ETL mutex would need to be implemented with GCC/Clang atomic builtins. |
I've been experimenting with the GCC/Clang implementation of atomics for the ETL. I have come up with a version that will only support types that are 'lock free'. Assuming
|
Also, compilation will fail with a |
On single core non-OS platforms we can also disable interrupt, like a critical section. This reminds me that on Windows, spin lock raises IRQ level before compare_exchange. So ISRs are blocked when the lock is acquired. (Actually on single core CPU raising IRQ level is the only thing that spin lock does)
Unfortunately on Cortex M4, only uint32_t or smaller is atomic... |
That would limit the max size of object that could be supported. What do you think about the idea of not supporting non-lock-free atomics? |
I've been reading an article about how user-space spinlocks should be avoided at all cost, due to OS thread scheduling issues. |
For me, I only use lock free ones. |
I also give the GCC atomic a try. It works for small structures, enums. But for large structures, it has 2 problems: First, GCC keeps complaining about
I have no idea about the difference. If I move them into a C file, the error is gone. But I suspect it's just hiding the problem. Second, if we want to make some lock for the data. We can't pass the per instance lock to the built-ins. So we have to use a global one. That's not good. |
Fixed 20.40.0 |
Hi,
In etl's atomic, when the data can't be accessed with compiler's lock-free statements, a spin lock is used.
But when trying to access those atomics from ISR, the spin lock can deadlock.
Here's an example:
LEDBlink.cpp
The "store" instruction in ISR will wait for "load" in main to release the lock. However since we are in ISR, the lock is never released.
The text was updated successfully, but these errors were encountered: