Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Nick Roberts <nickrob@snap.net.nz>
Cc: gdb@sources.redhat.com
Subject: Re: Merge of nickrob-async-20060513 to mainline?
Date: Fri, 06 Oct 2006 01:26:00 -0000	[thread overview]
Message-ID: <20061006012633.GA20001@nevyn.them.org> (raw)
In-Reply-To: <17701.43098.583849.540224@kahikatea.snap.net.nz>

On Fri, Oct 06, 2006 at 01:50:34PM +1300, Nick Roberts wrote:
>  > Ideally you'd be able to reuse the signal handler logic (see the calls
>  > to sigprocmask and sigsuspend) and thus not have a millisecond latency
>  > and excessive spinning.  That's actually a pretty important feature,
>  > because context switching to gdb every millisecond or so is going to
>  > really hurt performance of the debuggee.
> 
> From the event loop, GDB needs to detect that a process/thread has changed
> status and check for user input.  If it does the first with sigsuspend, the
> only way I can see how it can do the second is by using threads. This would
> almost take us back to where we started.

Correct.  You can't do it quite the same way.  The key is not
sigsuspend itself, but the use of signals, and blocking them when you
don't need them.

The easy way to combine the two would be with pselect, but it's
inadequately portable.  Here's a bit from the man page of that function
on my system, which explains a useful alternative:

       Since version 2.1, glibc has provided an emulation of pselect()
       that is implemented using sig- procmask(2) and select().  This
       implementation remains vulnerable to the very race condition
       that pselect() was designed to prevent.  On systems that lack
       pselect() reliable (and more portable) signal trapping can be
       achieved using the self-pipe trick (where a signal handler
       writes a byte to a pipe whose other end is monitored by select()
       in the main program.)

So when you want to wait, you make sure such a signal handler is
installed for SIGCHLD, unblock SIGCHLD, and call select on a set of fds
that includes the one written to by the signal handler.  If you get a
byte on that fd, you know there's a child ready to be waited for. When
you're done waiting, you re-block the signal.  It's possible to get
spurious wakeups this way (for instance if a signal is received between
the return of select and the re-blocking), but with a little care
everything works out OK.

This is actually pretty similar to the way you do it with threads.

Does that make sense?

-- 
Daniel Jacobowitz
CodeSourcery


  reply	other threads:[~2006-10-06  1:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-30  2:27 Nick Roberts
2006-08-30  2:33 ` Daniel Jacobowitz
2006-08-30  3:21   ` Nick Roberts
2006-08-30  4:01     ` Daniel Jacobowitz
2006-08-30 12:31       ` Eli Zaretskii
2006-08-30 21:34       ` Nick Roberts
2006-08-30 21:43         ` Daniel Jacobowitz
2006-08-30 23:45           ` Nick Roberts
2006-09-26  8:41           ` Nick Roberts
2006-09-26 12:38             ` Daniel Jacobowitz
2006-09-26 22:12               ` Nick Roberts
2006-09-26 22:24                 ` Daniel Jacobowitz
2006-09-26 23:40                   ` Nick Roberts
2006-09-29  1:50                   ` Nick Roberts
2006-10-06  0:53               ` Nick Roberts
2006-10-06  1:26                 ` Daniel Jacobowitz [this message]
2006-10-06  2:13                   ` Nick Roberts
2006-10-06  3:24                     ` Daniel Jacobowitz
2006-10-08  3:46                       ` Nick Roberts
2006-10-09 18:00                         ` async implies sync, was " Michael Snyder
2006-10-09 20:28                           ` async implies sync Nick Roberts
2006-08-31 21:03     ` Merge of nickrob-async-20060513 to mainline? Mark Kettenis
2006-08-31 21:49       ` Nick Roberts
2006-08-31 22:29         ` Daniel Jacobowitz
2006-08-31 22:40           ` Nick Roberts
2006-08-31 22:53             ` Michael Snyder
2006-08-31 23:33               ` Nick Roberts
2006-08-31 23:37                 ` Daniel Jacobowitz
2006-08-31 23:59                   ` Jim Ingham

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

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

  git send-email \
    --in-reply-to=20061006012633.GA20001@nevyn.them.org \
    --to=drow@false.org \
    --cc=gdb@sources.redhat.com \
    --cc=nickrob@snap.net.nz \
    /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