Passing shared delegates

Martin Drasar drasar at ics.muni.cz
Thu Jan 17 00:46:11 PST 2013


On 16.1.2013 22:53, Maxim Fomin wrote:
> Yes, it happens so (shared function made it a member). Casting away
> shared is UB but it can be done if your are sure.

Ok. But that leaves me with an unanswered question from one of my
previous posts.

What happens when you cast from and to shared? Is there any moving in
memory from TLS and back? Or does it just access the memory as if it
were in shared space?

I have tried to compare addresses of b and _b, but writeln refuses to
display an address of shared and assert does not help me either. But
using the inspection capabilities of VisualD I found out that they seem
to have the same address.

> Consider rewriting the code and eliminating unnecessary shareds and

I am afraid that the original code has as little shareds as possible.
But I have an idea how to rewrite it to avoid needing to access _b.

> please stop attaching "> " to each line of code.

Sorry about that. It is a habit that prevents Thunderbird from
linewrapping a code. If you have Thunderbird on receiving end then it is
no problem - you can copy the quoted code without those '>'. But I
understand that with other clients it might be irritating.

> To workaround add another method:
> 
> void callback(B b)
> {
>     _b.execute(&callback);
> }

Yes, that could help. But as I wrote before, I will rewrite it to avoid
this issue.

Thanks,
Martin


More information about the Digitalmars-d-learn mailing list