[Gc] Correct way to initialize with a given root set ?

Boehm, Hans hans.boehm at hp.com
Wed Nov 23 16:59:06 PST 2005


That mostly looks right to me.

I don't think there is reason to bother with clearing
GC_dont_precollect.  That's the default, which is correct.

For portability, it's best to call GC_INIT() from main, independent of
root registration issues.  You should need the GC_init() call only for
pre-7.0 GC versions, and only in a few cases, e.g. if you are using
thread-local allocation.  But it won't hurt to call both.

I doubt this stuff has been thoroughly tested by anyone ...

Hans

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com 
> [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Lothar Scholz
> Sent: Wednesday, November 23, 2005 2:41 PM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] Correct way to initialize with a given root set ?
> 
> 
> Hello,
> 
> I'm currently improving the SmallEiffel compiler and now i 
> need a way to define the root set for a multithreaded application.
> 
> Is this code snippet a correct way to initialize the program, 
> when i can be sure that all allocated memory is only 
> reachable with from the defined global variable set and the stack.
> 
> I can also safely assume from the generated code that all 
> pointers will always point to the base address return by GC_malloc().
> 
> --------------------------------------------------------------
> ---------------
> typedef struct var var_t;
> struct var {
>    void* one_root_var;
>    void* another_root_var;
> }
> var_t all_existing_global_vars;
> 
> int main() {
>    GC_all_interior_pointers = 0;
>    GC_dont_precollect = 0;
>    GC_no_dls = 0;
>    GC_init();
>    
>    char* roots = (char*)&all_existing_global_vars;
>    GC_clear_roots();
>    GC_add_roots (roots, roots + sizeof(all_existing_global_vars));
>    
>    <... and here we jump into the eiffel world...>
> }
> --------------------------------------------------------------
> ---------------
> 
> Does "GC_clear_roots" keep the stack of the main thread and 
> later created threads as root sets. I this code working on 
> all operating systems: Linux, BSD, Solaris, Win2K, WinXP, MacOSX ?
> 
> 
> -- 
> Best regards,
>  Lothar Scholz              mailto:scholz at scriptolutions.com
> 
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com 
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 



More information about the Gc mailing list