Re: MAX_BACKENDS size (comment accuracy)

From: Andres Freund <andres(at)anarazel(dot)de>
To: Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: MAX_BACKENDS size (comment accuracy)
Date: 2025-01-26 18:15:11
Message-ID: pwkanegtsb4pmzsgcnd76hnaxe2kmipaobxfrolb2p6rm63ef6@s6serexsgq7g
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2025-01-25 23:35:51 -0800, Jacob Brazeal wrote:
> While we are on the topic of comments from lwlock.c, there is one other one
> that confused me, in LWLockWaitListLock:

> * /* and then spin without atomic operations until lock is released */ {
> SpinDelayStatus delayStatus; init_local_spin_delay(&delayStatus); while
> (old_state & LW_FLAG_LOCKED) { perform_spin_delay(&delayStatus); old_state
> = pg_atomic_read_u32(&lock->state); }#ifdef LWLOCK_STATS delays +=
> delayStatus.delays;#endif finish_spin_delay(&delayStatus); }*
>
> It seems that we *are* using an atomic operation in the loop (though, no
> compare-and-set, etc.) I might be mis-reading the intent of the comment,
> but I'm curious if there's a way to reword it, too.

It's not really an atomic operation. It's just reading an atomic variable
(which just guarantees that the compiler isn't eliding the read and that the
read isn't torn). Personally I don't think there's a need to rephrase the
comment, but I probably wrote it, so take that with a grain of salt.

Greetings,

Andres Freund

PS: FYI, this list values properly quoting messages instead of replying ontop
of the entire quoted messages.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-01-26 19:04:41 Re: Using Expanded Objects other than Arrays from plpgsql
Previous Message Andres Freund 2025-01-26 18:10:35 Re: MAX_BACKENDS size (comment accuracy)