From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xin Wang Newsgroups: gmane.lisp.guile.user Subject: Re: The equivalent of racket's break-thread in guile? Date: Sun, 2 Jun 2013 07:49:01 +0800 Message-ID: References: <871u8ncvsn.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec51b9a4b41dc8004de20605a X-Trace: ger.gmane.org 1370130561 19398 80.91.229.3 (1 Jun 2013 23:49:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 1 Jun 2013 23:49:21 +0000 (UTC) Cc: guile-user@gnu.org To: =?ISO-8859-1?Q?Ludovic_Court=E8s?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 02 01:49:20 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UivXy-0007sy-6A for guile-user@m.gmane.org; Sun, 02 Jun 2013 01:49:18 +0200 Original-Received: from localhost ([::1]:52149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UivXx-0004jL-Pn for guile-user@m.gmane.org; Sat, 01 Jun 2013 19:49:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UivXn-0004hU-CI for guile-user@gnu.org; Sat, 01 Jun 2013 19:49:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UivXi-0007Yf-UW for guile-user@gnu.org; Sat, 01 Jun 2013 19:49:07 -0400 Original-Received: from mail-ve0-x233.google.com ([2607:f8b0:400c:c01::233]:59516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UivXi-0007Yb-Oa; Sat, 01 Jun 2013 19:49:02 -0400 Original-Received: by mail-ve0-f179.google.com with SMTP id d10so1990102vea.24 for ; Sat, 01 Jun 2013 16:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=luMXH1J2D+6dhVED0jDnr0hzFuFrpoxfOU0/ABzNCGM=; b=oCti3a4AR70p42h4MzSFw6UaGVk/qDW4e3mQKxc9YzKR6BFCxKiF4ibn4EvHzyCCE7 m4ahHg5cnmST1MReAVyF8ql7eYc16wgvMaUzKeCwuZNcs4k7azCunenvZyYrh7hiOzgi 0y4iX7dw0wuy96crwnWQ1LIdZusk9L2kZvqlEmpJHX3mbr+xOb/E13VdPOlJazaNFy5/ 29ERGZStvJZIf4zwcXHLWHbHQ/R+FPNDl0BWw3fmxCKT7oO6fNCrRVL4qwGo2fIRBb5F BgFT3vLvgrnzD1yoqvcIxlMZ8uUFu+ByH4Zid7ZTAkWdLzXPRUk+ecMvcnJkiJyMO951 CXTg== X-Received: by 10.52.38.161 with SMTP id h1mr12691599vdk.30.1370130542088; Sat, 01 Jun 2013 16:49:02 -0700 (PDT) Original-Received: by 10.58.74.8 with HTTP; Sat, 1 Jun 2013 16:49:01 -0700 (PDT) In-Reply-To: <871u8ncvsn.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400c:c01::233 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10401 Archived-At: --bcaec51b9a4b41dc8004de20605a Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 2013/5/31 Ludovic Court=E8s > Xin Wang skribis: > > > In Guile, the equivalent of kill-thread is cancel-thread, and is there > any > > equivalent of break-thread? > > > > [1] http://docs.racket-lang.org/reference/breakhandler.html > > If I understand correctly, =93breaks=94 are similar to Guile=92s =93async= s=94 > (info "(guile) Asyncs"). > > However, I don=92t understand what you=92re trying to achieve. Could you > give another example of the behavior you=92re after? > > I was reading source code of Arc language[1], and wondering if it is possible to port it to Guile. It define a function to handle HTTP request in srv.arc(L48): (def handle-request-1 (s) --- pruned --- (with (th1 nil th2 nil) (=3D th1 (thread (after (handle-request-thread i o ip) (close i o) (kill-thread th2)))) (=3D th2 (thread (sleep threadlife*) (unless (dead th1) (prn "srv thread took too long for " ip)) (break-thread th1) (force-close i o)))))))) It create two threads to handle a request, one do main stuff and anthor one wait to kill first one if it takes too much time. Although I'm not quite sure, I think one reason to use 'kill-thread' and 'break-thread' differently is to make sure that exception handler function is fully executed. ('after' is implemented by dynamic-wind). [1] http://ycombinator.com/arc/*arc3.1.tar* > Thanks, > Ludo=92. > > > --bcaec51b9a4b41dc8004de20605a Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable



2013/5/31 Ludovic Co= urt=E8s <ludo@gnu.org>
Xin Wang <dram.wang@gmail.com> skribis:

> In Guile, the equivalent of kill-thread is cancel-thread, and is there= any
> equivalent of break-thread?
>
> [1] http://docs.racket-lang.org/reference/breakhandler.html=

If I understand correctly, =93breaks=94 are similar to Guile=92s =93a= syncs=94
(info "(guile) Asyncs").

However, I don=92t understand what you=92re trying to achieve. =A0Could you=
give another example of the behavior you=92re after?


I was reading source code of Arc langu= age[1], and wondering if it is possible to port it to Guile.

<= div>It define a function to handle HTTP request in srv.arc(L48):

(def handle-request-1 (s)
=A0 --- pruned ---
=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (with (th1 nil th2 nil)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 (=3D th1 (thread
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 (after (handle-request-thread i o ip)
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (clos= e i o)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 (kill-thread th2))))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 (=3D th2 (thread
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 (sleep threadlife*)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (unless (dead th1)
=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (prn "srv thread t= ook too long for " ip))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (break-t= hread th1)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 (force-close i o))))))))

It create two threads to = handle a request, one do main stuff and anthor one wait to kill first one i= f it takes too much time.

Although I'm not quite sure, I think one reason to use &= #39;kill-thread' and 'break-thread' differently is to make sure= that exception handler function is fully executed. ('after' is imp= lemented by=A0 dynamic-wind).

=A0
Thanks,
Ludo=92.



--bcaec51b9a4b41dc8004de20605a--