May 14, 2021

On Friday, 14 May 2021 at 15:30:53 UTC, Markk wrote:

>

On Friday, 14 May 2021 at 15:21:30 UTC, Ola Fosheim Grøstad wrote:

>

On Friday, 14 May 2021 at 15:00:20 UTC, Markk wrote:

>

Yes, the problem is that spinning up a new thread is costly, and in order to get the benefits of "no final collection" the thread should be short lived.

I think thread pooling (along with the scoped release I described) and/or D's fibers address all of these concerns in very elegant ways.

Again, D is already very, very close.

_Mark

D rox ☀️

Let's improve it so it becomes perfect 😁

May 14, 2021

On Friday, 14 May 2021 at 13:48:12 UTC, Markk wrote:

>

Hi,

[...]

_Mark

I'm very much against binding any dynamic memory to any thread. It collides with a lot of programming models. For example threads created outside D, in C++ or any other language has no knowledge of D GC memory. This means that FFI is much more complicated.

Also threads are like prostitutes, they do the work of the client and then another client comes along doing some other work. Typically example are thread pools where any thread can do any work. Also bring fibers into the equation makes this even more unfitting.

Memory bounded to a thread is a bad idea and as time moves on it becomes more clear that a program should not assume which thread they are running (should only operate on self) and also not which CPU they are running on.

May 14, 2021

On Friday, 14 May 2021 at 15:37:22 UTC, IGotD- wrote:

>

On Friday, 14 May 2021 at 13:48:12 UTC, Markk wrote:

>

[...]

I'm very much against binding any dynamic memory to any thread. It collides with a lot of programming models. For example threads created outside D, in C++ or any other language has no knowledge of D GC memory. This means that FFI is much more complicated.

[...]

Kinda agree on this. A thread is a virtualization of the cpu and a process is a virtualization of the memory.

May 14, 2021
On Fri, May 14, 2021 at 01:48:12PM +0000, Markk via Digitalmars-d wrote: [...]
> D has this nice default per-thread static memory model, i.e. if I understand all this correctly, this allows for better, more natural thread safety, while it makes it generally unsafe to use this memory from other threads (without locking). I guess the same is implicitly true for stack memory.
> 
> Now could it equally make sense to use per-thread heaps?

It would be nice, because it would allow per-thread GC, which could address some of the problems people complain about the GC.

However, there's a big caveat: sharing data between threads would be essentially extremely broken.  Today, immutable can be safely shared across threads, because well, it's immutable.  But once allocations are bound to a thread, this sharing would be impossible without major problems.


> I.e. all allocations would need to be per thread, and it would be illegal to reference memory of one thread's heap, static memory, or stack from another thread's memory.
[...]

Yeah, this would be a major bugbear for implementing it in D.


T

-- 
If creativity is stifled by rigid discipline, then it is not true creativity.
May 14, 2021

On Friday, 14 May 2021 at 15:30:46 UTC, Adam D. Ruppe wrote:

>

On Friday, 14 May 2021 at 15:23:13 UTC, Markk wrote:

>

There's two types of programmer: the ones busy doing actual productive work and the ones with the spare time to complain about GC on the forum.

I agree with that statement, but then I also believe that D should address the GC concern. Given how close D already is, it would be a shame not to.

:-D

_Mark

May 14, 2021

On Friday, 14 May 2021 at 13:48:12 UTC, Markk wrote:

>

Just some thoughts after reading a handful Rust and D books... and after having seen so many wrinkle their noses at GC ... and therefore, unfortunately D.

_Mark

Isn't that what Nim already has, thread local garbage collection?

I thought there was a problem to equip that in D, I think it relates to traced vs non traced pointer, though I'm no expert on this.

I wanted to know more why we can't do this in D because I like the idea in general.

However, I'm favoring more a task based solution mentioned already by Ola, i.e. a green thread based local GC as you could to concurrency without threads.

May 14, 2021

On Friday, 14 May 2021 at 15:30:46 UTC, Adam D. Ruppe wrote:

>

On Friday, 14 May 2021 at 15:23:13 UTC, Markk wrote:

>

But look at even this forum. It seems to be one of the biggest no-gos for D.

There's two types of programmer: the ones busy doing actual productive work and the ones with the spare time to complain about GC on the forum.

nobody complain about the GC

people complain about the fact everything is modeled around the idea of a poors man GC, implemented and served to everyone by force

May 14, 2021
On Fri, May 14, 2021 at 04:25:47PM +0000, russhy via Digitalmars-d wrote:
> On Friday, 14 May 2021 at 15:30:46 UTC, Adam D. Ruppe wrote:
> > On Friday, 14 May 2021 at 15:23:13 UTC, Markk wrote:
> > > But look at even this forum. It seems to be one of the biggest no-gos for D.

IMO that impression is misleading, because those who are happy with the GC are silent and you don't hear from them, and the ones complaining about it are the vocal minority.


> > There's two types of programmer: the ones busy doing actual productive work and the ones with the spare time to complain about GC on the forum.
> 
> nobody complain about the GC

Oh the irony.


> people complain about the fact everything is modeled around the idea of a poors man GC, implemented and served to everyone by force

Nobody is forcing you to do anything. If you don't like D because of the GC, there's plenty of alternatives, like Rust, that people here seem to love talking about.  Nobody's twisting your arm that you must use D, and nobody's holding a gun to your head that you must use the GC.

:-D


T

-- 
Why do conspiracy theories always come from the same people??
May 14, 2021

On Friday, 14 May 2021 at 15:37:22 UTC, IGotD- wrote:

>

I'm very much against binding any dynamic memory to any thread. It collides with a lot of programming models. For example threads created outside D, in C++ or any other language has no knowledge of D GC memory. This means that FFI is much more complicated.

I disagree by 180°. If the memory management is associated with the thread, such "foreign" threads would be completely left alone by D or the GC, and that's exactly as it should be. Passing memory from/to that thread to a D thread is already a difficult thing to do right, this proposal would make that safer and more formal.

>

Also threads are like prostitutes, they do the work of the client and then another client comes along doing some other work. Typically example are thread pools where any thread can do any work.

Again, I disagree. Please read my earlier post about how the Allocator assignment could be scoped (e.g. by the pool bootstrapper) https://forum.dlang.org/post/mqfuxbuuhpvqeyvxoang@forum.dlang.org, Pool usage could be supported in a very natural way and be very fast, because for short tasks, the GC would never run and all the memory could be jettisoned en bloc when the thread task goes out of scope.

>

Also bring fibers into the equation makes this even more unfitting.

Obviously fibers need to share the same thread heap/Allocator. Other than that, scoping/RAII (of the pinned references) is still valid and this is the most important thing. The limitations/language guarantees would sometimes be overly strict between fibers of the same thread, but they are still valid. Fibers are scheduled cooperatively, i.e. non-preemtively, so the premise to make the GC simpler/faster, holds. So what is the problem, exactly?

>

Memory bounded to a thread is a bad idea and as time moves on it becomes more clear that a program should not assume which thread they are running (should only operate on self) and also not which CPU they are running on.

This contradicts everything I read about locality becoming more and more important with modern multi-core processors. The following is simply the best article I ever, ever read about the issue. I recommend reading it:

https://www.informit.com/articles/article.aspx?p=1609144

_Mark

May 14, 2021

On Friday, 14 May 2021 at 17:02:00 UTC, Markk wrote:

>

I disagree by 180°. If the memory management is associated with the thread, such "foreign" threads would be completely left alone by D or the GC, and that's exactly as it should be. Passing memory from/to that thread to a D thread is already a difficult thing to do right, this proposal would make that safer and more formal.

If for example C++ calls a D function, the D function does something temporary with arrays then those arrays will not be cleaned up if the array memory is thread local.

More likely since the thread has no meta data in D, some error will happen. The programmer will sure know it but this is very inconvenient as the D function will not work if called outside D.