pg_atomic_exchange_u32() in ProcArrayGroupClearXid()

From: Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: pg_atomic_exchange_u32() in ProcArrayGroupClearXid()
Date: 2018-09-21 17:35:28
Message-ID: CAPpHfdtxLsC-bqfxFcHswZ91OxXcZVNDBBVfg9tAWU0jvn1tQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

While investigating ProcArrayGroupClearXid() code I wonder why do we have
this loop instead of plain pg_atomic_exchange_u32() call? Is it
intentional?

/*
* Now that we've got the lock, clear the list of processes waiting for
* group XID clearing, saving a pointer to the head of the list. Trying
* to pop elements one at a time could lead to an ABA problem.
*/
while (true)
{
nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
&nextidx,
INVALID_PGPROCNO))
break;
}

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergei Kornilov 2018-09-21 17:38:16 Re: pgsql: Improve autovacuum logging for aggressive and anti-wraparound ru
Previous Message Pavel Stehule 2018-09-21 17:29:02 Re: proposal: prefix function