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: Fri, 31 May 2013 14:24:37 +0800 Message-ID: References: <1369972797.2610.57.camel@Renee-desktop.suse> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0122ee424caaf704ddfdab72 X-Trace: ger.gmane.org 1369981491 15237 80.91.229.3 (31 May 2013 06:24:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 May 2013 06:24:51 +0000 (UTC) Cc: guile-user@gnu.org To: Nala Ginrut Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri May 31 08:24:53 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 1UiIlg-0005NX-B7 for guile-user@m.gmane.org; Fri, 31 May 2013 08:24:52 +0200 Original-Received: from localhost ([::1]:38173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiIlf-00052c-PX for guile-user@m.gmane.org; Fri, 31 May 2013 02:24:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiIlV-00052D-CU for guile-user@gnu.org; Fri, 31 May 2013 02:24:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiIlR-0000qJ-SN for guile-user@gnu.org; Fri, 31 May 2013 02:24:41 -0400 Original-Received: from mail-vc0-f181.google.com ([209.85.220.181]:48778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiIlR-0000q9-Mt for guile-user@gnu.org; Fri, 31 May 2013 02:24:37 -0400 Original-Received: by mail-vc0-f181.google.com with SMTP id lf11so782937vcb.40 for ; Thu, 30 May 2013 23:24:37 -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=FciWlsQSoxUImEA2ewnxPK9XvqoXE/AMj86LjvIW8yQ=; b=znfcl+Wnny1QAli97jbALx5BtPBpayvnkfFybEvkqrRbZmz6GSywqTg7mQrHBCYUQZ juypHmwwmTmYvIR14+anExSDUAluPlR8FUaa5IOpMxNdNXowK8pdO2/Hk3VlmK45Lh5j OYDuIou9Wt5xNQRGJEbueH+wvAP5EEJgABV55yr9Vz1X3GJApNAxAWSuEQL1HRglJdv7 4iBqZqCJAIBC97PAjmUmY4/z3n8/tBgLZifSRnQvCc4RAH7nVytbN8tAHfr6FnYl3MVq kQc6Tt4xgseTdEIrCdza3V2H3T6u/p5lp2rymBB/AR8vVet4EAvmnwtPQmYkl6utwAeY fuNQ== X-Received: by 10.52.190.130 with SMTP id gq2mr7538716vdc.37.1369981477234; Thu, 30 May 2013 23:24:37 -0700 (PDT) Original-Received: by 10.58.74.8 with HTTP; Thu, 30 May 2013 23:24:37 -0700 (PDT) In-Reply-To: <1369972797.2610.57.camel@Renee-desktop.suse> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.181 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:10390 Archived-At: --089e0122ee424caaf704ddfdab72 Content-Type: text/plain; charset=ISO-8859-1 2013/5/31 Nala Ginrut > On Fri, 2013-05-31 at 07:40 +0800, Xin Wang wrote: > > In Racket, break-thread is used to send an break exception to a > thread[1]. > > > > E. g. > > > > (let ((th (thread (lambda () > > (dynamic-wind > > (lambda () #t) > > (lambda () (/ 1 0)) > > (lambda () (sleep 5) (display "out-guard\n"))))))) > > > > (sleep 1) > > (break-thread th)) > > > > For above code, out-guard part of dynmaic-wind will not be interrupted if > > use break-thread to cancel a thread, and kill-thread will cancel thread > > immediately. > > > > 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 > > > > I think the answer is NO. > > The thread in Racket is green-thread which is implemented by some kind > of stack-copying. That's why its thread could receive the so-called > 'break signal'. The scheduler is in the VM rather than OS. > But the traditional thread in Guile is based on pthread. So they are > very different. > Anyway, I'm trying to write green-thread based on delimited-continuation > which will be used for an Actor-model implementation. > > Thank you for pointing out this. After some more search, I found that pthread has function pthread_kill [1], which can be used to send signal to specific thread. No sure if it can be used to implement similar behaviour. [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html > > > Regards, > > Xin Wang > > > --089e0122ee424caaf704ddfdab72 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



2013/5/31 Nala Ginrut <nalaginrut= @gmail.com>
On Fri, 2013-05= -31 at 07:40 +0800, Xin Wang wrote:
> In Racket, break-thread is used to send an break exception to a thread= [1].
>
> E. g.
>
> (let ((th (thread (lambda ()
> =A0 =A0 =A0 =A0 =A0 =A0 (dynamic-wind
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda () #t)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda () (/ 1 0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda () (sleep 5) (display "out-gu= ard\n")))))))
>
> =A0 (sleep 1)
> =A0 (break-thread th))
>
> For above code, out-guard part of dynmaic-wind will not be interrupted= if
> use break-thread to cancel a thread, and kill-thread will cancel threa= d
> immediately.
>
> 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=
>

I think the answer is NO.

The thread in Racket is green-thread which is implemented by some kind
of stack-copying. That's why its thread could receive the so-called
'break signal'. The scheduler is in the VM rather than OS.
But the traditional thread in Guile is based on pthread. So they are
very different.
Anyway, I'm trying to write green-thread based on delimited-continuatio= n
which will be used for an Actor-model implementation.


Thank you for pointing out this.
After some more search, I found that pthread has function pthr= ead_kill [1], which can be used to send signal to specific thread.

No sure if it can be used to implement similar behaviour.
=A0

> Regards,
> Xin Wang



--089e0122ee424caaf704ddfdab72--