From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: thread cancellation, take 2 Date: Sun, 23 Sep 2007 12:42:43 +0200 Message-ID: <87vea1oe70.fsf@chbouib.org> References: <2bc5f8210709200730q61d7973ft8d1da14889efb2f1@mail.gmail.com> <87abrhl604.fsf@laas.fr> <2bc5f8210709200836i1267bcc8qa066b4d27f2c3e2@mail.gmail.com> <2bc5f8210709222216rf7aa8ednd380fa8db2975073@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1190544226 14918 80.91.229.12 (23 Sep 2007 10:43:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 23 Sep 2007 10:43:46 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Sep 23 12:43:41 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 1IZOw9-00041t-FO for guile-devel@m.gmane.org; Sun, 23 Sep 2007 12:43:41 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IZOw6-0002bw-Vz for guile-devel@m.gmane.org; Sun, 23 Sep 2007 06:43:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IZOw3-0002bZ-Ih for guile-devel@gnu.org; Sun, 23 Sep 2007 06:43:35 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IZOw1-0002bB-UF for guile-devel@gnu.org; Sun, 23 Sep 2007 06:43:34 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IZOw1-0002b8-RM for guile-devel@gnu.org; Sun, 23 Sep 2007 06:43:33 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IZOw1-0003bj-Bx for guile-devel@gnu.org; Sun, 23 Sep 2007 06:43:33 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IZOvp-0003XJ-HZ for guile-devel@gnu.org; Sun, 23 Sep 2007 10:43:21 +0000 Original-Received: from adh419.fdn.fr ([80.67.176.9]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Sep 2007 10:43:21 +0000 Original-Received: from ludo by adh419.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Sep 2007 10:43:21 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 82 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: adh419.fdn.fr X-URL: http://www.laas.fr/~lcourtes/ X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: i486-pc-linux-gnu User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:BJN5A0jhIUn99ErHndZbOLbSBGE= X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) 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:6809 Archived-At: Hi Julian, "Julian Graham" writes: > Alright -- I think I've got it working. After mucking about for a bit > with asyncs, I realized that it makes more sense to evaluate cleanup > handlers in do_thread_exit -- and evaluation should happen there > anyway, since pthreads says cleanup handlers get called when the > thread exits for any reason, not just cancellation. Duh. Good! > The patch I've attached adds three new public functions: > cancel-thread, push-thread-cleanup, and pop-thread-cleanup. API > documentation on their behavior is included in the changes. Thinking a bit more about it, maybe we could let users handle the list of handlers if needed. That is, we'd have just `set-thread-cleanup-procedure!' (a two-argument procedure whose first arg is a thread) and `thread-cleanup-procedure' (a one-argument procedure); users who have cleanup code spread over several procedure would provide a procedure that iterates over such pieces of code. That would keep Guile's built-in mechanisms minimal. What do you think? > I've never submitted a patch for Guile before, so I've likely made a > few mistakes in formatting, etc., and I don't really know the vetting > procedure. I hope I've gotten the main bits right, though. Please let > me know if there are any changes I should make. First, you'll need to assign copyright to the FSF so that we can incorporate your changes (I'll send you the relevant stuff off-line). Then, you need to make sure your code follows the GNU Standards as much as possible (a few comments follow). Also, please add a few test cases to `threads.test' that exercise the new API. I think the patch adds a useful feature so, unless someone raises an objection, I'd be OK to apply it to HEAD when you're done with the copyright paperwork. > +static SCM handle_cleanup_handler(void *cont, SCM tag, SCM args) { > + *((int *) cont) = 0; > + return scm_handle_by_message_noexit(NULL, tag, args); > + return SCM_UNDEFINED; > +} The second `return' is superfluous. Also, for clarity and consistency with the GCS, the function should rather read: static SCM cleanup_handler_error_handler (void *cont, SCM tag, SCM args) { int *continue_p = (int *) cont; *continue_p = 0; return scm_handle_by_message_noexit (NULL, tag, args); } But if you agree with the change I suggested above (removing the list of handlers), you no longer need that function: you can just use `scm_handle_by_message_noexit ()' directly. > + while(!scm_is_eq(t->cleanup_handlers, SCM_EOL)) > + { > + int cont = 1; > + SCM ptr = SCM_CAR(t->cleanup_handlers); > + t->cleanup_handlers = SCM_CDR(t->cleanup_handlers); Please add a whitespace before opening parentheses. > +SCM_DEFINE (scm_cancel_thread, "cancel-thread", 1, 0, 0, > + (SCM thread), > +"Asynchronously force the target @var{thread} to terminate. @var{thread} " > +"cannot be the current thread, and if @var{thread} has already terminated or " > +"been signaled to terminate, this function is a no-op.") Better indent the doc string. Thanks, Ludovic. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel