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

Janice Caron caron800 at googlemail.com
Thu Sep 13 15:38:14 PDT 2007


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!

OK - so it /could/ be implemented as a library function then.

You'd have to unconst not just the mutex, but also the data that the
mutex was protecting. But that's OK too - it's mutex protected. That
could all be built into the smart pointer.

...what a pity D doesn't do smart pointers. Should we start a thread
on that? I must assume that it's been discussed before.

So it would be:

struct A
{
    int x;
}

Shared!(A) shared_a;
{
    scope a = new Readable!(A)(shared_a);
    int n = a.dereference.x;
}
{
    scope a = new Writeable!(A)(shared_a);
    a.derefence.x = 4;
}

There has a be a better syntax than a.dereference.x though, even if we
don't have operator arrow.

Anyway - I think you've cracked it. Nice one!



More information about the Digitalmars-d mailing list