unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* thread cancellation, take 2
@ 2007-09-20 14:30 Julian Graham
  2007-09-20 15:18 ` Ludovic Courtès
  0 siblings, 1 reply; 23+ messages in thread
From: Julian Graham @ 2007-09-20 14:30 UTC (permalink / raw)
  To: guile-devel

Hi Guilers,

  A while back I did some work on introducing a thread cancellation
API into Guile's thread code.  At the time, the thread refactor for
1.8 hadn't yet happened, and I didn't really know enough about Guile
internals to get anything working.  I came back to my code recently
and made another attempt to integrate it, and I STILL couldn't make it
work, but now at least I think I know the right questions to ask.

  What I had in mind for thread cancellation is a set of three
functions that mirrors the pthreads API: cancel-thread,
push-thread-cleanup, and pop-thread-cleanup (as with pthreads,
push-thread-cleanup and pop-thread-cleanup respectively add and remove
expressions to and from a stack that is evaluated at the time
cancel-thread is called).  My implementation involves installing a
real pthreads cancellation handler that manages evaluation of Scheme
cleanup handlers and some thread shutdown behavior (although most of
this is handled by the new on_thread_exit stuff).  The problem I'm
having comes, I think, when I try to evaluate the items on the cleanup
list -- because the cancellation handler stack is the result of a
non-local exit from Guile's normal execution, I think there's
something wrong with the state of the stack boundaries or registers
that makes the GC freak out (heap corruption, I think, leading to a
double free() somewhere down the road) when I do an eval in that
context (whether or not I'm in Guile mode).  So: Is there a way to
safely evaluate SCMs from C after a JMP into a weird context?  (I
imagine the on_thread_exit code is called in a similar state, but it
only superficially manipulates SCM values...)  I've tried explicitly
resetting the top and base pointers of the stack, as well as updating
the register window, but that didn't seem to help.

  (At the time I asked about this originally, Marius Vollmer suggested
that cancellation be implemented as a system-async -- I think that
approach leaves us with the same issues regarding the GC / stack,
especially now that Guile threads are isomorphic to pthreads.)

  On a related note, do you guys have any preferences as to the
behavior of cancel-thread?  The way I've got it now, joining threads
will receive the value of the final expression in the cleanup-handler
list as the "result" of the canceled thread.  Does that make sense?
Also, should the items in the cleanup-handlers list be S-exprs or
should I limit them to being thunks (kind of leaning toward the latter
right now...)?


Thanks,
Julian


P.S. Here's a link to the thread from when I first tried to do this:

http://lists.gnu.org/archive/html/guile-devel/2004-10/msg00075.html


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2007-10-30  9:35 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-20 14:30 thread cancellation, take 2 Julian Graham
2007-09-20 15:18 ` Ludovic Courtès
2007-09-20 15:36   ` Julian Graham
2007-09-23  5:16     ` Julian Graham
2007-09-23 10:42       ` Ludovic Courtès
2007-09-23 18:39         ` Julian Graham
2007-09-24 11:42           ` Ludovic Courtès
2007-09-24 15:39             ` Julian Graham
2007-09-24 20:17               ` Julian Graham
2007-09-26  4:03               ` Ludovic Courtès
2007-09-27  2:39                 ` Julian Graham
2007-10-18  0:41                   ` Julian Graham
2007-10-20 11:12                     ` Ludovic Courtès
2007-10-20 13:02                     ` Ludovic Courtès
2007-10-20 22:19                       ` Julian Graham
2007-10-21 13:03                         ` Ludovic Courtès
2007-10-21 13:11                           ` Ludovic Courtès
2007-10-23 14:16                             ` Julian Graham
2007-10-24  2:35                               ` Julian Graham
2007-10-29 22:04                                 ` Ludovic Courtès
2007-10-29 22:20                                   ` Julian Graham
2007-10-29 23:23                                     ` Neil Jerram
2007-10-30  9:35                                       ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).