| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | Andres Freund <andres(at)anarazel(dot)de>, Peter Eisentraut <peter(at)eisentraut(dot)org> |
| Cc: | Nathan Bossart <nathandbossart(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: convert various variables to atomics |
| Date: | 2026-08-06 08:37:46 |
| Message-ID: | 3856d1cf-53a8-414b-98d9-829d5a455a86@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 04/08/2026 17:32, Andres Freund wrote:
> On 2026-08-04 16:07:58 +0200, Peter Eisentraut wrote:
>> On 23.07.26 21:56, Nathan Bossart wrote:
>>> On Wed, Jul 22, 2026 at 09:31:49AM -0400, Nathan Bossart wrote:
>>>> Ah. It looks like we could use 0 as the sentinel and simplify the call
>>>> sites. They subtract one before calling SetStartupBufferPinWaitBufId() and
>>>> add one after calling GetStartupBufferPinWaitBufId().
>>>
>>> I added a new prerequisite patch (v2-0004) that does this.
>>
>> Maybe this is okay, but there are a bunch more places (not touched by your
>> patches) that mix unsigned atomics operations with actually signed values.
>> Stuff like PIDs and proc numbers. I think for better overall hygiene and to
>> simplify broader adoption, perhaps we should introduce support for signed
>> atomic variables.
>
> I'm quite hesitant to do that, at least without a lot more clear cut examples
> where it actually would make the code better. I think it's rarely a good idea
> to use signed variables for atomics, because you get undefined behaviour on
> overflow, there's problems with bit masking, etc. IME most data in atomically
> modified should actually be unsigned and probably should have been unsigned
> before the conversion to atomics.
We could provide pg_atomic_read/write_i32() and
pg_atomic_compare_exchange_i32() but leave out fetch-and-add and other
such instructions that have overflow or bit masking issues.
- Heikki
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2026-08-06 08:51:09 | Re: Wrong query result w/ propgraph single lateral col reference |
| Previous Message | Chao Li | 2026-08-06 08:36:36 | Re: pg_createsubscriber: allow duplicate subscription names |