Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Markus Elfring Newsgroups: comp.programming.threads,comp.unix.programmer Subject: Re: Safe accesses of global arrays in signal handlers? Date: Sun, 30 Sep 2012 14:04:32 +0200 Lines: 28 Message-ID: <50683550.10906@web.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Trace: individual.net OvoXkif7fS15BIuXrIN7egFJ8OjEBv0oknxEuIDfopc8v+sRfpBViiwl5vdeJ6EE98 Cancel-Lock: sha1:6cxdfikLbEjPI/W1xXvHIvtvmC4= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 In-Reply-To: Xref: csiph.com comp.programming.threads:1126 comp.unix.programmer:3388 > What do you mean by shared? A global variable as the one that is used in your small source code example. (Its data will be reused by other functions after it was eventually set by a signal handler.) > For example, assigning to an element of a file scoped array like this should be fine: I have got doubts here. https://www.securecoding.cert.org/confluence/display/seccode/SIG31-C.+Do+not+access+or+modify+shared+objects+in+signal+handlers > volatile sig_atomic_t foo[NSIG]; > > void handler(int signo) { > foo[signo] = 1; > } The access for a specific single integer can be performed atomically. Does this situation change when the shown index is involved? Do C/C++ compilers deal with pointer arithmetic in this use case which might result in a portability issue? Do any implementations or software platforms exist which guarantee that the property "async-signal-safety" will be maintained here? Regards, Markus