Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #1122

Re: Safe accesses of global arrays in signal handlers?

Message-ID <rggkj9-4fn.ln1@wilbur.25thandClement.com> (permalink)
From William Ahern <william@wilbur.25thandClement.com>
Subject Re: Safe accesses of global arrays in signal handlers?
Newsgroups comp.programming.threads, comp.unix.programmer
References (3 earlier) <pan.2012.09.27.12.35.52.872000@nowhere.com> <aclh4pFol46U1@mid.individual.net> <pan.2012.09.28.17.26.06.856000@nowhere.com> <aco59lFcohrU1@mid.individual.net> <pan.2012.09.29.19.37.07.356000@nowhere.com>
Date 2012-09-29 17:31 -0700

Cross-posted to 2 groups.

Show all headers | View raw


Nobody <nobody@nowhere.com> wrote:
> On Sat, 29 Sep 2012 13:44:50 +0200, Markus Elfring wrote:

> >> Yes. write() is async-signal-safe, so one thread can do a blocking
> >> read() and the signal handler can use write() to wake it.
> > 
> > Thanks for your feedback.
> > 
> > Do you see any difficulties or software design challenges for proper
> > handling of the situation that more data is written into the pipe than
> > the receiving thread can read and process in a timely manner?

> The signal handler only needs to write one byte at a time; the receiving
> thread can read a pipe-full at a time. If the receiving thread does
> nothing but notify worker threads or enqueue messages, there shouldn't be
> a problem.

> But you have a similar issue with the signals themselves. If non-realtime
> signals are generated faster than they are handled, pending signals aren't
> guaranteed to be queued, i.e. the handler may only be invoked once for
> multiple signals.

The problematic issue is when SIGFOO fills the pipe, causing SIGBAR to get
dropped on the floor. That seems exceedingly unlikely, but I suppose you
could use one pipe per signal.

Or better yet, just use a pipe for signalling and an atomic operation to
clear a separate data structure, basically mimicking what the kernel does
with it's pending queue and syscall interruption.

FWIW, Linux has signalfd, and the BSDs have the EVFILT_SIGNAL kevent. The
proper solution on Solaris is to block all signals, and have a dedicated
thread block on sigwait, sigwaitinfo, or sigtimedwait. That also works on
Linux and most of the BSDs--OpenBSD threads and signals are currently
broken, however.

EVFILT_SIGNAL is the cleanest interface, because it requires no global data
structures and its use has no side effects--multiple pollers can catch
notifications, and it works regardless of whether a signal is blocked or
ignored.

If only every platform implemented kqueue...

Back to comp.programming.threads | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-25 08:01 +0200
  Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-25 12:15 +0100
    Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-27 11:20 +0200
      Re: Safe accesses of global arrays in signal handlers? Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-09-27 13:23 +0100
        Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-28 13:25 +0200
      Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-27 13:35 +0100
        Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-28 13:48 +0200
          Re: Safe accesses of global arrays in signal handlers? Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-09-28 18:34 +0200
            Re: Safe accesses of global arrays in signal handlers? scott@slp53.sl.home (Scott Lurndal) - 2012-09-28 17:54 +0000
          Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-28 18:26 +0100
            Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-29 13:44 +0200
              Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-29 20:37 +0100
                Re: Safe accesses of global arrays in signal handlers? William Ahern <william@wilbur.25thandClement.com> - 2012-09-29 17:31 -0700
                Signal handlers writing into pipes Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 13:21 +0200
                Re: Safe accesses of global arrays in signal handlers? Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-10-01 18:04 +0100
                Signal handlers writing into pipes Markus Elfring <Markus.Elfring@web.de> - 2012-10-03 16:36 +0200
                Re: Signal handlers writing into pipes Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-10-03 17:07 +0100
                Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 13:12 +0200
                Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-30 20:46 +0100
        Re: Safe accesses of global arrays in signal handlers? Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2012-09-28 13:39 +0100
        Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-29 13:15 +0200
          Re: Safe accesses of global arrays in signal handlers? William Ahern <william@wilbur.25thandClement.com> - 2012-09-29 17:42 -0700
            Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 14:04 +0200
  Re: Safe accesses of global arrays in signal handlers? Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-09-25 13:27 +0100

csiph-web