From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Julian Graham" Newsgroups: gmane.lisp.guile.devel Subject: thread cancellation, take 2 Date: Thu, 20 Sep 2007 10:30:14 -0400 Message-ID: <2bc5f8210709200730q61d7973ft8d1da14889efb2f1@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1190298643 4560 80.91.229.12 (20 Sep 2007 14:30:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Sep 2007 14:30:43 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Sep 20 16:30:33 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IYN2v-0000r9-O5 for guile-devel@m.gmane.org; Thu, 20 Sep 2007 16:30:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IYN2t-0004py-F9 for guile-devel@m.gmane.org; Thu, 20 Sep 2007 10:30:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IYN2q-0004n7-8J for guile-devel@gnu.org; Thu, 20 Sep 2007 10:30:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IYN2n-0004hV-FD for guile-devel@gnu.org; Thu, 20 Sep 2007 10:30:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IYN2n-0004h7-8x for guile-devel@gnu.org; Thu, 20 Sep 2007 10:30:17 -0400 Original-Received: from fk-out-0910.google.com ([209.85.128.191]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IYN2m-00066O-Us for guile-devel@gnu.org; Thu, 20 Sep 2007 10:30:17 -0400 Original-Received: by fk-out-0910.google.com with SMTP id 19so629923fkr for ; Thu, 20 Sep 2007 07:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=/TbwyK5fGA7ldjs2MqMwtxcOUJ9dJJ6lyzx/Rdi9MhY=; b=LrMASegnWQPRrCbKJMz9jkfN8nYM1UPcwdx58p3kourxb1FpIvv2Kj6vgcZ/DfV6+u9Sul3RnFHkjXcSgzJlTLg2fZXt+deRaK1A690acikGxfp7q9icL75NUdf4z07pbwQg3E5myCDJvhmrG8HNQyXlXWhhBGY0fSJtm5dTWSw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=RTYXIF6U/I66xcfJAnhNzzZYjPS9DIHDnmICYQH+Fts+pqY6pMESYoEfqx8LxAAvnZ2npNhdA+azzJZ0Sr6wEzSL+RQloQjCAKa0Sy48gEMfjKRVcA6coR7RHeO73ZR9+wRlqfyFO9ulNp+T+JxHLUXIkr5qM4YJZJd/aQz8GdI= Original-Received: by 10.82.177.3 with SMTP id z3mr843425bue.1190298614885; Thu, 20 Sep 2007 07:30:14 -0700 (PDT) Original-Received: by 10.82.175.11 with HTTP; Thu, 20 Sep 2007 07:30:14 -0700 (PDT) Content-Disposition: inline X-Detected-Kernel: Linux 2.6 (newer, 2) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6803 Archived-At: 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