public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59785] New: atomic_store should load source operand atomically?
@ 2014-01-13 11:37 ma.jiang at zte dot com.cn
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
0 siblings, 2 replies; 3+ messages in thread
From: ma.jiang at zte dot com.cn @ 2014-01-13 11:37 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/59785] atomic_store should load source operand atomically?
2014-01-13 11:37 [Bug c/59785] New: atomic_store should load source operand atomically? ma.jiang at zte dot com.cn
@ 2014-01-13 12:33 ` jakub at gcc dot gnu.org
2014-01-14 1:11 ` ma.jiang at zte dot com.cn
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-13 12:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59785
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |jakub at gcc dot gnu.org
Resolution|--- |INVALID
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is atomic store, not atomic load, what do you expect?
The only reason for taking val as a pointer rather than the value itself is
that some values really need to live in memory and the API is generic. If you
are trying to pass an address of a var that is modified by other threads, it is
just a bug in your source code, you likely want to do an atomic load into a
temporary automatic variable etc. which won't be modified by other threads and
only then atomic_store it.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/59785] atomic_store should load source operand atomically?
2014-01-13 11:37 [Bug c/59785] New: atomic_store should load source operand atomically? ma.jiang at zte dot com.cn
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
1 sibling, 0 replies; 3+ messages in thread
From: ma.jiang at zte dot com.cn @ 2014-01-14 1:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59785
--- Comment #2 from ma.jiang at zte dot com.cn ---
Ok, Thanks for the reply. I know what you mean. A atomic_store is not
responsible for loading the source operand atomically as it is just a store.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-14 1:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-13 11:37 [Bug c/59785] New: atomic_store should load source operand atomically? ma.jiang at zte dot com.cn
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
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).