This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++0x Memory model and gcc
- From: Ian Lance Taylor <iant at google dot com>
- To: Albert Cohen <Albert dot Cohen at inria dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 09 May 2010 21:39:55 -0700
- Subject: Re: C++0x Memory model and gcc
- References: <4BE5774B.3090709@bourguet.org> <4BE5C741.7070504@inria.fr>
Albert Cohen <Albert.Cohen@inria.fr> writes:
> Jean-Marc Bourguet wrote:
>>> -fmemory-model=single
>>> Assume single threaded execution, which also means no signal
>>> handlers.
>>> -fmemory-model=fast
>>> The user is responsible for all synchronization. Accessing
>>> the same memory words from different threads may break
>>> unpredictably.
>>> -fmemory-model=safe
>>> The compiler will do its best to protect you.
>>
>> With that description, I'd think that "safe" lets the user code assumes
>> the sequential consistency model. I'd use -fmemory-model=conformant or
>> something like that for the model where the compiler assumes that the user
>> code respect the constraint led out for it by the standard. As which
>> constraints are put on user code depend on the languages -- Java has its
>> own memory model which AFAIK is more constraining than C++ and I think Ada
>> has its own but my Ada programming days are too far for me to comment on
>> it -- one may prefer some other name.
>
> I agree. Or even, =c++0x or =gnu++0x
>
> On the other hand, I fail to see the differen between =single and
> =fast, and the explanation about "the same memory word" is not really
> relevant as memory models typically tell you about concurrent accesses
> to "different memory words".
What I was thinking is that the difference between =single and =fast
is that =single permits store speculation. The difference between
=fast and =safe/=conformant is that =fast permits writing to a byte by
loading a word, changing the byte, and storing the word; in
particular, =fast permits write combining in cases where =safe does
not.
Memory models may not talk about memory words, but they exist
nevertheless.
Ian