From: Chris Hecker <checker@d6.com>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] gc question: thread stacks, fibers, etc.
Date: Mon, 14 Oct 2002 00:18:41 -0700 [thread overview]
Message-ID: <4.3.2.7.2.20021013222805.01b51428@mail.d6.com> (raw)
In-Reply-To: <20021013103223.E13771@pauillac.inria.fr>
>An alternative is to allocate the stack outside the heap, and scan it
>via scanning hooks like the thread library does, but manipulate it
>from the Caml side through a proxy, heap-allocated custom block. The
>custom block has a finalization function that the GC will call when no
>reference to the proxy (i.e. to the fiber) remain. The finalization
>function can then decide to kill the fiber (free its stack) if it so
>pleases.
But this doesn't solve the original problem of the fiber containing a
reference to itself on its stack (or any fiber points to any other fiber),
right? The scanning hook functions assume they're scanning roots, so they
can't check for circularity and release the whole mess. The function I
need is something that says "the values I'm sending to the scanner are not
stored in roots, so check for circularities that includes them". Or
something like that. Make sense? Perhaps there's a way to hook that in
the gc? Maybe I'm missing something.
Anyway, ignoring the circularity problem for the moment, deleting the stack
from under a fiber works because the stack itself can never have a pointer
from the heap into it, so it's always okay to delete (according to your
answer to my other question). I guess you'd have to be careful that no C
functions that were still on the stack of that fiber had ever passed a
pointer into their stack to anyone who keeps it elsewhere (which in
ordinary cases is okay, since when writing the C code you assume you'll get
returned-to in an orderly fashion). Maybe that's an okay constraint to
place on code, but a bug of that nature would certainly be hard to find, so
maybe it's not okay (this is why people shouldn't kill threads, nb. the
other thread :).
Hmm, now that I think about it, I can just use an exception for this,
exactly like the other caml-list discussion was wishing it could for
threads. In other words, I'm only ever going to consider toasting a fiber
when it's yielded, so when the fiber gets resumed it'll be in the yield
code. That code can check whether the gc has requested finalization of the
fiber, and throw an exception back up through the fiber. That will solve
all the stack issues, because the exception will unwind it all, and the
fiber can catch it if it wants and do any cleanup.
Yes, that's much cleaner than just killing it anyway. That just leaves the
circularity issue above.
Thanks!
Chris
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
prev parent reply other threads:[~2002-10-14 7:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-04 10:25 Chris Hecker
2002-10-06 18:13 ` [Caml-list] Coroutines Jerome Vouillon
2002-10-06 19:46 ` Chris Hecker
2002-10-12 15:58 ` John Max Skaller
2002-10-12 16:33 ` [Caml-list] gc question: thread stacks, fibers, etc John Max Skaller
2002-10-12 18:54 ` Chris Hecker
2002-10-13 8:32 ` Xavier Leroy
2002-10-14 7:18 ` Chris Hecker [this message]
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=4.3.2.7.2.20021013222805.01b51428@mail.d6.com \
--to=checker@d6.com \
--cc=caml-list@inria.fr \
--cc=xavier.leroy@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