On Sun, Dec 4, 2011 at 6:19 PM, Timon Gehr <timon.g...@gmx.ch> wrote: > On 12/04/2011 11:32 PM, Andrew Wiley wrote: >> >> On Sun, Dec 4, 2011 at 4:23 PM, Andrei Alexandrescu >> <seewebsiteforem...@erdani.org> wrote: >>> >>> On 12/4/11 4:16 PM, Andrew Wiley wrote: >>> >>>> >>>> So it looks like right now, message passing is copying objects, which >>>> seems very bad. Check this out: >>>> -------- >>>> import std.stdio; >>>> import std.concurrency; >>>> >>>> class Bob { >>>> } >>>> >>>> void main() { >>>> >>>> auto tid = spawn(&func); >>>> auto bob = new shared(Bob)(); >>>> writeln("bob is currently at ", cast(void*)(&bob)); >>> >>> >>> >>> This is the address of the reference, not that of the object. Use >>> cast(void*)(bob). >>> >>> Andrei >> >> >> Ah, I am covered with shame. >> >> In that case, no object copying is occurring, and I have message >> passing for immutable objects working, although my current solution is >> basically to check whether the object is immutable, and if so, memcpy >> the reference. That breaks immutability, but only for the reference, >> and I don't think there's any alternative unless we get tail >> const/immutable into the language. >> >> I'm guessing this is too hackish to get merged into std.variant? > > > You might want to have a look at std.typecons.Rebindable.
The problem with Rebindable is that internally, it looks like this: union { T value; immutable(T) visibleValue; } This fails the check in std.concurrency for aliases to thread-local mutable data. I *could* cast to and from shared to avoid this, but then I've just exchanged a local hack in variant for one that crosses thread boundaries.