Walter is right about transitive readonly - here's the alternative

Steven Schveighoffer schveiguy at yahoo.com
Fri Sep 14 05:49:52 PDT 2007


"Janice Caron" <caron800 at googlemail.com> wrote in message 
news:mailman.216.1189723099.16939.digitalmars-d at puremagic.com...
> On 9/13/07, Bruno Medeiros <brunodomedeiros+spam at com.gmail> wrote:
>> Erm, you could always cast away the constness of the mutex, so I think
>> it's possible. (even if not ideal)
>
> You're right. I hadn't thought of that.
>
> 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":

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=58383

-Steve 





More information about the Digitalmars-d mailing list