public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ma.jiang at zte dot com.cn" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59785] New: atomic_store should load source operand atomically? Date: Mon, 13 Jan 2014 11:37:00 -0000 [thread overview] Message-ID: <bug-59785-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59785 Bug ID: 59785 Summary: atomic_store should load source operand atomically? Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ma.jiang at zte dot com.cn gcc provide a atomic_store interface as below. void __atomic_store (type *ptr, type *val, int memmodel) In manual, There is only a simple description ---"This is the generic version of an atomic store. It stores the value of *val into *ptr." But it seemed that this interface could not do what the description said when *val is a global memory which might be messed up by other threads. unsigned long long int ta=123; unsigned long long int tb=321; int test() { __atomic_store(&tb, &ta, __ATOMIC_RELAXED); return 0; } On ARM,the codes above give out a assembly instruction sequence as below. movw r3, #:lower16:ta movt r3, #:upper16:ta ldrd r0, [r3] movw r3, #:lower16:tb movt r3, #:upper16:tb .L3: ldrexd r4, r5, [r3] strexd r2, r0, r1, [r3] cmp r2, #0 bne .L3 the source operand ta was not fetched atomically, so we might get a totally wrong num from tb when ta were modified by other threads. I guess the atomic_store interface only provide a function as--"fetch val non-atomically ,and then store it into ptr atomically." This is exactlly what the gimple tree shows. test () { long long unsigned int ta.0; int D.4127; ta.0 = ta; __atomic_store_8 (&tb, ta.0, 0); D.4127 = 0; return D.4127; } I think it would be better to give a more detailed desctription in the manual. Or make a atomical load in the atomic_store.
next reply other threads:[~2014-01-13 11:37 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-01-13 11:37 ma.jiang at zte dot com.cn [this message] 2014-01-13 12:33 ` [Bug c/59785] " jakub at gcc dot gnu.org 2014-01-14 1:11 ` ma.jiang at zte dot com.cn
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=bug-59785-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).