unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: mark.d.witmer@gmail.com
To: guile-user@gnu.org
Subject: Re: A timely question on interrupted system calls
Date: Thu, 11 Jul 2013 21:26:21 -0700	[thread overview]
Message-ID: <87ppuojtea.fsf@mark-desktop.PK5001Z> (raw)
In-Reply-To: 87ppupe1vg.fsf@gnu.org

ludo@gnu.org (Ludovic Courtès) writes:

> mark.d.witmer@gmail.com skribis:
>
>> I followed the thread a few days ago on @guile-dev about SCM_SYSCALL and
>> was grateful I hadn't run into any problems with it. But now I have!
>
> Excellent.  :-)
>
>> I'm working with an event loop for my X bindings that polls a socket for
>> availablity using `select'. Meanwhile, I have a repl server running in
>> another thread. When something connects to the server, the call to
>> `select' get interrupted and throws a system error. In the following
>> code the catch expression doesn't catch the system error:
>
> Could it be that it’s actually the other thread that gets EINTR?

Thanks for the insights. I figured out what I was doing wrong... it was
actually a result of my not understanding dynamic states well enough.

I had some parameters in use in the main thread that I wanted to share
with the repl thread, so I figured it wouldn't hurt to do something like
this:

(define dynamic-state (current-dynamic-state))
(with-dynamic-state dynamic-state
  (make-thread
     (lambda ()
       ... start repl ...)))

But of course that was the cause of all my problems. The tag that
`throw' uses when it aborts to the catch prompt is captured as an
argument to a function stored in a fluid, so it's sensitive to
manipulations of the dynamic state like this. Basically, the system
error was throwing to a different (make-prompt-tag "catch") than the
(make-prompt-tag "catch") my catch was set up to handle. D'oh! It didn't
really have much to do with system calls or errors at all.

I think the correct way to make parameters in different threads refer to
the same object is like this:

(define my-param-value (my-param))
(make-thread
  (lambda ()
    (parameterize ((my-param my-param-value))
     ...)))

It feels a bit hackish, but sometimes I like the nested dynamic scope
behavior of parameters even when I don't want the thread sandboxing.

-- 
Mark Witmer




      reply	other threads:[~2013-07-12  4:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-11  6:45 A timely question on interrupted system calls mark.d.witmer
2013-07-11 12:07 ` Ludovic Courtès
2013-07-12  4:26   ` mark.d.witmer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ppuojtea.fsf@mark-desktop.PK5001Z \
    --to=mark.d.witmer@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).