Re: Should we standardize on a type for signal handler flags?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Should we standardize on a type for signal handler flags?
Date: 2017-06-06 17:33:38
Message-ID: 22866.1496770418@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Sun, Jun 4, 2017 at 7:21 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
>> Well, we already have some variables that aren't actually booleans,
>> although I think all of them are only read not manipulated in signal
>> handlers (InterruptHoldoffCount etc). So one could argue that there's
>> no safety benefit in sig_atomic_t, because we're already using in other
>> places.

> I think that's a pretty good argument, really. If there exists a
> platform where only sig_atomic_t is safe to read from a signal
> handler, then we already don't work on that platform. Even saving and
> restoring errno isn't safe in that case.

That's an argument from false premises. The question here is what types
are safe for an interrupt handler to *change*, not what can it read.

Having said that, this is a good point:

>> We also already rely on int32 stores being atomic in other
>> parts of the code, although that's between processes not between signal
>> / normal path of execution.

> I don't think the issues are much different.

That would license us to use int32 communication variables, but it still
doesn't mean that "bool" is safe.

In practice, the sort of architecture where bool would be a problem is
one that doesn't have narrower-than-word-wide memory access instructions,
so that changing a char-sized variable involves loading a word,
manipulating a byte within the word, and storing it back. I cut my
teeth on some machines like that, but I dunno if any still exist in
the wild.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Petr Jelinek 2017-06-06 17:36:13 Re: Get stuck when dropping a subscription during synchronizing table
Previous Message Andres Freund 2017-06-06 17:30:50 Re: Should we standardize on a type for signal handler flags?