www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - GC via low-priority thread

reply "Luis Marques" <luismarques gmail.com> writes:
Hello,

I've been wondering, I've read on this newsgroup that one could use a
low-priority thread to do GC, perhaps setting watermarks of memory usage after
which that thread's priority would raise.

What I question is the following. Here http://digitalmars.com/d/memory.html says
that "All threads other than the collector thread must be halted while the
collection is in progress". So, wouldn't you still experience the halting that
makes GC problematic? Or the ideia supposed to be that more frequent GC cycles
would make each cycle faster and imperceptible? But in that case I can't really
see how the thread priority would matter much.

PS: I hope this is the right newsgroup to discuss this, I suppose my last post
should have been sent to .learn, but my first reaction was "that doesn't work as
the docs say!"

Luís Marques
Jun 23 2006
parent Sean Kelly <sean f4.ca> writes:
Luis Marques wrote:
 Hello,
 
 I've been wondering, I've read on this newsgroup that one could use a
 low-priority thread to do GC, perhaps setting watermarks of memory usage after
 which that thread's priority would raise.
 
 What I question is the following. Here http://digitalmars.com/d/memory.html
says
 that "All threads other than the collector thread must be halted while the
 collection is in progress". So, wouldn't you still experience the halting that
 makes GC problematic?
The mark/sweep method of garbage collection must "stop the world" for at least a portion of its processing to make sure that it hasn't missed anything (Boehm does have a "mostly parallel mark/sweep GC implementation that reduces the time that the world is stopped, however). When people usually mention a low-priority thread performing GC they're thinking of incremental GC where a "stop the world" phase typically isn't required at all. Instead, garbage collection is happening perpetually in the background at a relatively low priority.
 Or the ideia supposed to be that more frequent GC cycles
 would make each cycle faster and imperceptible? But in that case I can't really
 see how the thread priority would matter much.
For mark/sweep, it shouldn't. Once the world is stopped, the GC thread should perform at normal priority by default since all other threads in the program are blocked. Sean
Jun 23 2006