[Bug target/109166] Built-in __atomic_test_and_set does not seem to be atomic on ARMv4T

jdx at o2 dot pl gcc-bugzilla@gcc.gnu.org
Sun Mar 19 07:37:35 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109166

--- Comment #3 from Jan Dubiec <jdx at o2 dot pl> ---
I do not get what "but that requires more" means in this context.

Lets assume that two threads test and set the same memory location which
initial value is 0 ("unlocked"/"false"). Now, when the first thread gets
preempted (a timer interrupt is requested) just after LDRB (i.e.
__atomic_test_and_set will return 0) and it happens that the second thread gets
its time slot, then it may happen that __atomic_test_and_set called by the
second thread also will return 0 and bam! – both threads will have "exclusive"
access to a shared resource. See get_lock() from sample libatomic as a typical
example of TAS usage:
https://gcc.gnu.org/wiki/Atomic/GCCMM?action=AttachFile&do=view&target=libatomic.c.


More information about the Gcc-bugs mailing list