Immutable Message Passing

Graham St Jack Graham.StJack at internode.on.net
Sun Dec 4 17:16:29 PST 2011


My vote is for something like immutable(Object) ref, as Andrew suggested 
earlier. This would allow mutable references to immutable objects to be 
passed through a message channel without nasty typecasting.

std.typecons.Rebindable has always been an ugly hack that doesn't quite 
do the job. Certainly every attempt I have made to use it has ended 
unhappily, and I end up redesigning to not pass objects between threads.

What is the status of the immutable(Object) ref proposal? Is it on the 
list of things to do, or is it ruled out? If it is ruled out, then what 
is the superior proposal?


On 05/12/11 10:49, Timon Gehr wrote:
> On 12/04/2011 11:32 PM, Andrew Wiley wrote:
>> On Sun, Dec 4, 2011 at 4:23 PM, Andrei Alexandrescu
>> <SeeWebsiteForEmail at 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.


-- 
Graham St Jack



More information about the Digitalmars-d mailing list