GC via low-priority thread
Sean Kelly
sean at f4.ca
Fri Jun 23 09:11:34 PDT 2006
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
More information about the Digitalmars-d
mailing list