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

Lothar Scholz scholz at scriptolutions.com
Wed Nov 23 14:40:45 PST 2005


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



More information about the Gc mailing list