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: Mon, 3 Jun 2013 09:37:45 +0800 Message-ID: References: <871u8ncvsn.fsf@gnu.org> <87vc5wtycc.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01176d89f009d204de36024f X-Trace: ger.gmane.org 1370223488 16970 80.91.229.3 (3 Jun 2013 01:38:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Jun 2013 01:38:08 +0000 (UTC) Cc: Guile User To: =?ISO-8859-1?Q?Ludovic_Court=E8s?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jun 03 03:38:09 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 1UjJiq-0003rd-M0 for guile-user@m.gmane.org; Mon, 03 Jun 2013 03:38:08 +0200 Original-Received: from localhost ([::1]:40202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjJip-0007CC-Td for guile-user@m.gmane.org; Sun, 02 Jun 2013 21:38:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjJib-0007C3-OO for guile-user@gnu.org; Sun, 02 Jun 2013 21:38:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjJiV-0002Y4-8L for guile-user@gnu.org; Sun, 02 Jun 2013 21:37:53 -0400 Original-Received: from mail-ve0-x22c.google.com ([2607:f8b0:400c:c01::22c]:45089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjJiV-0002Xy-2I; Sun, 02 Jun 2013 21:37:47 -0400 Original-Received: by mail-ve0-f172.google.com with SMTP id jz10so2407354veb.17 for ; Sun, 02 Jun 2013 18:37:46 -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=aIPRb9TvcDuHYnZiywTH4Txyj+K9nd6dnZ1nxnSMiwE=; b=yLdwUln0TNaiWShUhURhcp0seOlPcEWUO7Sx7M3Og4WEIdQQRvmLhLxNfPdiPb675W DT92w7Ff7L0taEDXD0DnnG/qx+SOUVORDsZgcgjlcQrGWTWM9d1i4UmPinXbbKaImLDC vFNyZ/Sv8irPKKXV8LqtU+HzW7Q/RsMhqku6gMR2IC2VoLljYVIOZzRD6X25/BW0Nl/r +q0E1Wpjspw+CS+xb+u8phdw1YLrHblCZJkt7tKHEUjo7p4zlO14oB92RiJ4xNkmcgjh Gjij7lj65QvRodVegndRDSYMYNGjXeuI9RnnQ8M7Bq6YBsdVwc18MMaqOqeycxnY6tr4 G09Q== X-Received: by 10.58.37.165 with SMTP id z5mr16382430vej.12.1370223465716; Sun, 02 Jun 2013 18:37:45 -0700 (PDT) Original-Received: by 10.58.74.8 with HTTP; Sun, 2 Jun 2013 18:37:45 -0700 (PDT) In-Reply-To: <87vc5wtycc.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::22c 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:10405 Archived-At: --089e01176d89f009d204de36024f Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 2013/6/2 Ludovic Court=E8s > Xin Wang skribis: > > > 2013/5/31 Ludovic Court=E8s > > > >> Xin Wang skribis: > >> > >> > In Guile, the equivalent of kill-thread is cancel-thread, and is the= re > >> 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 =93as= yncs=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. > > Here =91break-thread=92 in the first thread appears to be equivalent to > Guile=92s =91cancel-thread=92. > Do you mean 'kill-thread' in the first thread? > > Although I'm not quite sure, I think one reason to use 'kill-thread' an= d > > 'break-thread' differently is to make sure that exception handler > function > > is fully executed. ('after' is implemented by dynamic-wind). > > Hmm, I guess I still don=92t understand what =91break-thread=92 is suppos= ed to > do. > > Ludo=92. > --089e01176d89f009d204de36024f Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable



2013/6/2 Ludovic Cou= rt=E8s <ludo@gnu.org>
Xin Wang <dram.wang@gmail.com> skribis:

> 2013/5/31 Ludovic Court=E8s <ludo@g= nu.org>
>
>> Xin Wang <dram.wang@gmai= l.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/breakhan= dler.html
>>
>> If I understand correctly, =93breaks=94 are similar to Guile=92s = =93asyncs=94
>> (info "(guile) Asyncs").
>>
>> However, I don=92t understand what you=92re trying to achieve. =A0= 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)
> =A0 --- pruned ---
> =A0 =A0 =A0 =A0 =A0 =A0 (with (th1 nil th2 nil)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (=3D th1 (thread
> =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 (close i o= )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (kill-thre= ad th2))))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (=3D th2 (thread
> =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(unless (dead th1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(prn "srv thre= ad took too long for " ip))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(break-thread th1)
> =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 antho= r one
> wait to kill first one if it takes too much time.

Here =91break-thread=92 in the first thread appears to be equiv= alent to
Guile=92s =91cancel-thread=92.

Do you m= ean 'kill-thread' in the first thread?


> Although I'm not quite sure, I think one reason to use 'kill-t= hread' and
> 'break-thread' differently is to make sure that exception hand= ler function
> is fully executed. ('after' is implemented by =A0dynamic-wind)= .

Hmm, I guess I still don=92t understand what =91break-thread=92 is su= pposed to do.

Ludo=92.

--089e01176d89f009d204de36024f--