Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Bardur Arantsson <spam@scientician.net>
To: caml-list@inria.fr
Subject: Re: Stopping a value from getting GC'd
Date: Wed, 17 Aug 2005 07:36:50 +0200	[thread overview]
Message-ID: <dduidi$bsa$1@sea.gmane.org> (raw)
In-Reply-To: <ad8cfe7e050816211242a5faa@mail.gmail.com>

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'


  reply	other threads:[~2005-08-17  5:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-17  4:12 [Caml-list] " Jonathan Roewen
2005-08-17  5:36 ` Bardur Arantsson [this message]
2005-08-18  1:31   ` Cost of register_global_root (was: Stopping a value from getting GC'd) Nathaniel Gray
2005-08-18  2:40     ` [Caml-list] Cost of register_global_root Alain Frisch
2005-08-18  5:19       ` Nathaniel Gray
2005-08-18  3:57     ` [Caml-list] Cost of register_global_root (was: Stopping a value from getting GC'd) Markus Mottl
2005-08-18 17:13       ` skaller
2005-08-18 10:51     ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='dduidi$bsa$1@sea.gmane.org' \
    --to=spam@scientician.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox