What's wrong with D's templates?

grauzone none at example.net
Fri Dec 25 08:43:30 PST 2009


Walter Bright wrote:
> grauzone wrote:
>> What will you do?
> 
> Because of casting, there cannot be a thread-local only gc.

I think this is a very bad idea. I thought TLS by default was just the 
beginning of separating threads better. While it will work in the 
initial stages of D2, I don't think it should be final.

Also, it's bad how inter-thread communication will trigger GC runs, 
which will stop all threads in the process for a while. Because you have 
no choice but to allocate your immutable messages from the shared heap. 
That can't be... I must be missing some central point.

> This does not make the gc inherently unusable. Java, for example, uses 
> only one shared gc. It must, because Java has no concept of thread local.

What does Java matter here? Java was designed twenty years aho, when 
multicore wasn't an issue yet. D2 is designed *now* with good multicore 
support in mind.

Also I'm not sure if you're right here. Java has a generational copying 
GC, and although I don't know Sun Java's implementation at all, I'm 
quite sure the younger generation uses an entirely thread local heap. In 
the normal case, it shouldn't need to get a single lock to allocate 
memory. Just an unsynchronized pointer incrementation to get the next 
memory block (as fast as stack allocation). If a memory block "escapes" 
to the older generation (the GC needs to detect this case anyway), the 
memory can be copied to a shared heap.

This means old dumb Java will completely smash your super multicore 
aware D2. At least if someone wants to allocate memory... oh by the way, 
no way to prevent GC cycles on frequent memory allocations, even if the 
programmer knows that the memory isn't needed anymore: it seems manual 
memory managment is going to be deemed "evil". Or did I hear wrong that 
"delete" will be removed from D2?

By the way... this reminds me of Microsoft's Singularity kernel: they 
achieve full memory isolation between processes running in the same 
address, space without extending the type system with cruft like 
immutable. Processes can communicate like Erlang threads using the actor 
model.



More information about the Digitalmars-d mailing list