From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.user Subject: Re: The equivalent of racket's break-thread in guile? Date: Sun, 2 Jun 2013 08:34:44 +0800 Message-ID: References: <871u8ncvsn.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff1cdccba9afc04de210315 X-Trace: ger.gmane.org 1370133297 7254 80.91.229.3 (2 Jun 2013 00:34:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Jun 2013 00:34:57 +0000 (UTC) Cc: Guile User , =?UTF-8?Q?Ludovic_Court=C3=A8s?= To: Xin Wang Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 02 02:34:59 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 1UiwGA-0001o9-Je for guile-user@m.gmane.org; Sun, 02 Jun 2013 02:34:58 +0200 Original-Received: from localhost ([::1]:55397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiwGA-0001lb-5p for guile-user@m.gmane.org; Sat, 01 Jun 2013 20:34:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiwFz-0001lM-2q for guile-user@gnu.org; Sat, 01 Jun 2013 20:34:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiwFx-0003ig-RI for guile-user@gnu.org; Sat, 01 Jun 2013 20:34:47 -0400 Original-Received: from mail-ob0-x231.google.com ([2607:f8b0:4003:c01::231]:37746) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiwFx-0003iZ-KX; Sat, 01 Jun 2013 20:34:45 -0400 Original-Received: by mail-ob0-f177.google.com with SMTP id ta17so5203958obb.22 for ; Sat, 01 Jun 2013 17:34:44 -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=QD+PrWf9RY0d3aQt+eKSBHg0Ri4ihjyu42lZTfcFOvs=; b=TqtUNv7EqBB9FJ9osl/uZq3fQ1YlzubTDbwvUTfnw+e+MIvjcLSEmW22CkfnS4S/I+ cWgHLPgwbP5mnv+ZRIBGttmX1LYNDPWfqF99kXERKE8FcxZNHhp8dDuUj93ietZlRkbm PDo+EZ97n/L8SyETVkMTTE3h0lJ6jPOL3pK3K8K48K+29xexUo1lUy6zWa9Law/0ovBR aspcag2lLnmvu0ARccfEQCoJJpVwWMd5NNJZN+Xi8yk32xcazK5xJ+xslOXg+fygmBa5 0xdUyQZhbpZrIN1czyTkQOXkeMBNfFswyrfyaGBvAv4GPRnAhV/gDgzyhZGrqz5mJrz9 /GPg== X-Received: by 10.182.237.77 with SMTP id va13mr8158251obc.65.1370133284688; Sat, 01 Jun 2013 17:34:44 -0700 (PDT) Original-Received: by 10.182.95.5 with HTTP; Sat, 1 Jun 2013 17:34:44 -0700 (PDT) Original-Received: by 10.182.95.5 with HTTP; Sat, 1 Jun 2013 17:34:44 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::231 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:10402 Archived-At: --e89a8ff1cdccba9afc04de210315 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable If you just need to handle HTTP request or build webapp, I suggest you use my web framework Artanis. It uses Guile inner sever based on thread. =E5=9C=A8 2013-6-2 AM7:49=EF=BC=8C"Xin Wang" =E5=86=99= =E9=81=93=EF=BC=9A > > > > 2013/5/31 Ludovic Court=C3=A8s > >> 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, =E2=80=9Cbreaks=E2=80=9D are similar to Guile= =E2=80=99s =E2=80=9Casyncs=E2=80=9D >> (info "(guile) Asyncs"). >> >> However, I don=E2=80=99t understand what you=E2=80=99re trying to achiev= e. Could you >> give another example of the behavior you=E2=80=99re 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 functio= n > is fully executed. ('after' is implemented by dynamic-wind). > > [1] http://ycombinator.com/arc/*arc3.1.tar* > > >> Thanks, >> Ludo=E2=80=99. >> >> >> > --e89a8ff1cdccba9afc04de210315 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

If you just need to handle HTTP request or build webapp, I s= uggest you use my web framework Artanis. It uses Guile inner sever based on= thread.

=E5=9C=A8 2013-6-2 AM7:49=EF=BC=8C"Xin Wang= " <dram.wang@gmail.com&g= t;=E5=86=99=E9=81=93=EF=BC=9A



2013/5/31 Ludovic Court=C3=A8s <ludo@gnu.= org>
Xin Wang <dram.wang@gmail.com> sk= ribis:

> 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, =E2=80=9Cbreaks=E2=80=9D are similar to Gu= ile=E2=80=99s =E2=80=9Casyncs=E2=80=9D
(info "(guile) Asyncs").

However, I don=E2=80=99t understand what you=E2=80=99re trying to achieve. = =C2=A0Could you
give another example of the behavior you=E2=80=99re 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)
=C2=A0 --- pruned ---
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (with (th1 nil th2 nil)
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (=3D th1 (thread
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (after (handle-request-thread i o ip)
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (c= lose i o)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (kill-thread th2))))
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (=3D th2 (thread
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (sleep threadlife= *)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (unless (de= ad th1)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (prn "srv thread took too long for " ip))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (break-thread th1= )
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (force-clos= e 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 muc= h 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=C2=A0 dynamic-wind).

=C2=A0
Thanks,
Ludo=E2=80=99.



--e89a8ff1cdccba9afc04de210315--