Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news2.arglkargh.de!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!reader01.nrc01.news.zen.net.uk.POSTED!not-for-mail From: Nobody Subject: Re: Safe accesses of global arrays in signal handlers? Date: Sat, 29 Sep 2012 20:37:07 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.programming.threads,comp.unix.programmer References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 22 Organization: Zen Internet NNTP-Posting-Host: 31268699.news.zen.co.uk X-Trace: DXC=JRT0>1L[g60Z][238HZlA>a0UP_O8AJo<=dR0\ckLKG0WeZ<[7LZNR6Ea?> 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.