[Gc] Using the Boehm-Demers-Weiser GC with a new threading library

Ben Hutchings ben.hutchings at businesswebsoftware.com
Tue May 3 08:02:04 PDT 2005


Stephane Epardaud wrote:
> Hello,
> 
> I am developing a threading library, and wish to make it work with your 
> GC. As I understand this may very well not be trivial, and by no means 
> would I ask you to work on this task, I thought at least I could ask you 
> for some information as to how I should proceed.
<snip>
> I've looked a bit at the linux_threads.c file in your GC, and it looks 
> very clear and documented. The only thing it seems I would have to do in 
> the end is to restrict the GC scanning of parts of some GC_malloc'ed 
> blocks. But maybe I'm completely missing something ?

The GC calls the thread support module to find stacks, so you can 
allocate the cooperative thread stacks with GC_malloc_atomic and then 
control which parts are actually scanned by modifying the thread support 
functions.

The interface that each thread support module provides to the collector is:

/* Push all potential heap pointers on all thread stacks onto the   */
/* mark stack.                                                      */
void GC_push_all_stacks(void);
/* Push any potential heap pointers used by the thread support code */
/* that aren't members of the root set onto the mark stack.         */
void GC_push_thread_structures(void);
/* Suspend all heap-using threads other than the current thread     */
/* (and block creation of more heap-using threads).                 */
void GC_stop_world(void);
/* Resume all suspended heap-using threads.                         */
void GC_start_world(void);

If you start from the linux_threads implementation I think you'll only 
need to change GC_push_all_stacks.  Use GC_push_all to push the active 
part of each cooperative thread stack on the mark stack.

Ben.


More information about the Gc mailing list