guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hacking on 1.7 threads


From: Rob Browning
Subject: Re: hacking on 1.7 threads
Date: Sat, 23 Oct 2004 21:16:48 -0500
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Julian Graham <address@hidden> writes:

> What about heap data?  That is, if I'm storing a list SCM in an
> scm_thread struct that's allocated on the heap, and I cons stuff
> onto it, do I have to do anything special to prevent the GC from
> collecting the SCM contents of the struct?  Does the fact that it's
> a list (i.e., a chain of pairs) that I'm trying to protect make a
> difference?  (I'm assuming that if the head element gets marked, all
> the CDRs will get marked as well.)

If the head is marked, then yes, all the other list elements will be
marked too.

In general, on the C side, only SCM values on the stack will be seen
automatically by the GC.  So any values that are global, static, or
heap allocated must be made visible to the GC explicitly.

This can be done by adding the values to a Scheme side structure
you're already maintaining (one whose lifetime will be longer than the
SCM values in question), or by calling scm_gc_protect_object.  If you
use scm_gc_protect_object, you can call scm_gc_unprotect_object when
you're finished with the value.  The protect and unprotect calls may
be nested, and they'll involve a hash-table operation or so.

There's also a scm_permanent_object function that you can use for
objects that should never go away.  It's a bit cheaper than
scm_gc_protect_object -- basically just something like (set!
*protected-list* (cons obj *protected-list*)).

-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]