Fully transitive const is not necessary

Steven Schveighoffer schveiguy at yahoo.com
Wed Apr 2 12:47:03 PDT 2008


"Janice Caron" wrote
> On 02/04/2008, guslay wrote:
>>  You have just made the mistake to assume that const implies thread-safe.
>
> No I didn't. I stated that const is a /necessary/ condition for thread
> safety, but nowhere did I claim it was a /sufficient/ condition.
>
> I assumed (demonstrated, in fact), that mutable implies thread-unsafe,
> but not that const implies thread-safe. There is a difference.

Here is the full context:

> >  What mutable does is allowing finer-grained control over the powerful 
> > const system. It does not weaken it, it controls its scope. Those are 
> > orthogonal issues (as far as I have yet to see an instance where having 
> > half the fields of an object const, instead of all the fields of the 
> > object, limits anything in any way).
>
> Really?
>
>     class C
>     {
>         int x;
>         mutable int y; // just pretend this is legal
>     }
>
>     void f(const(C) c)
>     {
>         int temp = y;
>         y = temp + 1;
>     }
>
> Now imagine two threads calling f simultaneously with the same c.
> Imagine a thread switch occurs between the two statements.

guslay is saying "mutable gives you finer control over const, does not 
weaken it..."

You are saying "Really? <example that proves mutable const is not 
thread-safe>"

I think guslay interpreted your response as a rebuttal to his argument, and 
so he thought (as I did) that what you were saying is:

"Really?  Here's an example that is not thread safe (but is if mutable isn't 
allowed)"

In reality, I think your example has nothing to do with the difference 
between transitive and logical const at all.

-Steve 





More information about the Digitalmars-d mailing list