Walter is right about transitive readonly - here's the alternative
Steven Schveighoffer
schveiguy at yahoo.com
Fri Sep 14 07:07:24 PDT 2007
"Janice Caron" wrote
> On 9/14/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>> > And un-consting a mutex is probably the one place where it's
>> > absolutely safe to do so, no matter that other threads might be
>> > sharing it! Hot dang! That's brilliant!
>>
>> Hm.. The spec says that the result of casting away const and then
>> modifying
>> the variable is "undefined." I take this to mean that the compiler may
>> do
>> some optimizations based on the fact that you have a const object, and
>> then
>> your code might not behave as you think in some future version of D :(
>>
>> Although I think it has been suggested by Walter that casting away const
>> is
>> acceptable if "you know what you're doing":
>
> Well, Walter's only mentioned one problem so far, which is that of an
> object which the compiler things is const being shared between
> multiple threads. Though strictly speaking overriding const is
> undefined, we do, in fact, know what would happen. Thread A would make
> a modification, and then thread B would see the change.
That sounds like a definition :)
To me, undefined means "I can't tell you what happens, my compiler is free
to make assumtions that you cannot anticipate." What you are describing is
more like "not recommended".
-Steve
More information about the Digitalmars-d
mailing list