Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Stopping a value from getting GC'd
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bardur Arantsson <spam@s...>
Subject: Re: Stopping a value from getting GC'd
Jonathan Roewen wrote:
> Hi,
> 
> I have the following in my C code:
> 
> struct caml_thread_struct {
> 	char * bottom_of_stack;
> 	unsigned long last_retaddr;
> 	value * gc_regs;
> 	char * exception_pointer;
> 	struct caml__roots_block * local_roots;
> 	int is_running;
> 	value closure;
> };
> 
> typedef struct caml_thread_struct * caml_thread_t;
> 
> static value Val_thread(caml_thread_t thread) {
> 	CAMLparam0();
> 	CAMLlocal1(rv);
> 	rv = caml_alloc(1, Abstract_tag);
> 	Field(rv,0) = (value) thread;
> 	CAMLreturn(rv);
> }
> 
> #define Thread_val(rv) ((caml_thread_t)Field((rv),0))
> 
> Now my question is, since my Thread.t is abstract, once I pass my
> value to my Thread.create, there'll soon be nothing referencing the
> closure for the thread that's visible by the GC.
> 
> If I'm correct, the GC would then be allowed to reclaim this closure.
> So how do I stop the GC from doing that?
> 

register_global_root (or as some others would say: RTFM).

-- 
Bardur Arantsson
<bardur@imada.sdu.dk>
<bardur@scientician.net>

- Oh, did I say corpse hatch? I meant... innocence tube.
                                  Montgomery Burns, 'The Simpsons'