public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: robin.farine@terminus.org To: gcc-gnats@gcc.gnu.org Cc: acnrf@dial.eunet.ch Subject: libstdc++/3584: arm-specific atomic operations not atomic Date: Fri, 06 Jul 2001 02:56:00 -0000 [thread overview] Message-ID: <20010706094636.12604.qmail@sourceware.cygnus.com> (raw) >Number: 3584 >Category: libstdc++ >Synopsis: arm-specific atomic operations not atomic >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Fri Jul 06 02:56:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Robin Farine >Release: gcc version 3.0 >Organization: >Environment: build/host: Debian GNU/Linux target: arm-unknown-elf >Description: Routines such as atomic_add() that reads a memory location, apply an operation to the read value, uses the swp instruction to update the memory location and swp again if the value read the 2nd time does equal the initial value introduce a race condition. The attachment illustrates such a case. >How-To-Repeat: >Fix: For single CPU systems, disable thread scheduling during the operation. >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="arm-atomic-add.txt" Content-Disposition: inline; filename="arm-atomic-add.txt" The atomic_add() for ARM (with instructions numbering): static inline void __attribute__ ((__unused__)) __atomic_add (volatile _Atomic_word *__mem, int __val) { _Atomic_word __tmp, __tmp2, __tmp3; __asm__ __volatile__ ( "\n" "0:\t" 1 "ldr %0, [%3] \n\t" 2 "add %1, %0, %4 \n\t" 3 "swp %2, %1, [%3] \n\t" 4 "cmp %0, %2 \n\t" 5 "swpne %1, %2, [%3] \n\t" 6 "bne 0b \n\t" 7 "" : "=&r"(__tmp), "=&r"(__tmp2), "=&r"(__tmp3) : "r" (__mem), "r"(__val) : "cc", "memory"); } Example of sequence that produces an invalid result (*__mem == 2 instead of 4 at the end): T1 (%0 %1 %2) T2 (%0 %1 %2) *__mem 1 (x x x) __val=1 0 2 (0 x x) 3 (0 1 x) <-- reschedule 1 (x x x) __val=1 2 (0 x x) 3 (0 1 x) 4 (0 1 0) 1 5 (0 1 0) 6 (0 1 0) 7 (0 1 0) ... <-- reschedule 4 (0 1 1) 1 5 (0 1 1) <-- reschedule 1 (x x x) __val=2 2 (1 x x) 3 (1 3 x) 4 (1 3 1) 3 5 (1 3 1) 6 (1 3 1) 7 (1 3 1) .... <-- reschedule 6 (0 3 1) 1 1 (0 3 1) 2 (1 3 1) 3 (1 2 1) 4 (1 2 1) 2 5 (1 2 1) 6 (1 2 1) 7 (1 2 1) ....
next reply other threads:[~2001-07-06 2:56 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-07-06 2:56 robin.farine [this message] 2001-07-11 8:46 Richard Earnshaw 2001-07-11 10:36 Robin Farine 2001-07-11 11:06 Richard Earnshaw 2001-07-12 7:16 Robin Farine 2001-07-12 7:26 Richard Earnshaw 2002-05-31 18:09 pme 2002-10-03 9:17 rearnsha
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20010706094636.12604.qmail@sourceware.cygnus.com \ --to=robin.farine@terminus.org \ --cc=acnrf@dial.eunet.ch \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).