The "no gc" crowd

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 10 10:31:34 PDT 2013


On Thursday, October 10, 2013 19:23:14 Joseph Rushton Wakeling wrote:
> On 09/10/13 06:25, Andrei Alexandrescu wrote:
> > The way I see it we must devise a robust solution to that, NOT consider
> > the
> > state of the art immutable (heh, a pun).
> 
> Must say I have had a miserable experience with immutability and any kind of
> complex data structure, particularly when concurrency is involved.
> 
> As a practical fact I've often found it necessary to convert to immutable
> (not always via a cast or std.conv.to; sometimes via assumeUnique) to pass
> a complex data structure to a thread, but then to convert _away_ from
> immutable inside the thread in order for that data (which is never actually
> mutated) to be practically usable.
> 
> I'm sure there are things that I could do better, but I did not find a
> superior solution that was also performance-friendly.

std.concurrency's design basically requires that you cast objects to shared or 
immutable in order to pass them across threads (and using assumeUnique is 
still doing the cast, just internally). And then you have to cast them back to 
thread-local mutable on the other side to complete the pass and make the 
object useable again. There's really no way around that at this point, not 
without completely redesigning shared. Arguably, it's better to use shared 
when doing that rather than immutable, but at least in the past, shared hasn't 
worked right with std.concurrency even though it's supposed to (though that's 
an implementation issue rather than a design one, and it might be fixed by now 
- I haven't tried recently). And whether you're using shared or immutable, 
you're still having to cast.

I'm honestly surprised that Andrei is rejecting the idea of casting to/from
shared or immutable being normal given how it's required by our current
concurrency model. And changing that would be a _big_ change.

- Jonathan M Davis


More information about the Digitalmars-d mailing list