pg_atomic_exchange_u32() in ProcArrayGroupClearXid() - Mailing list pgsql-hackers

From Alexander Korotkov
Subject pg_atomic_exchange_u32() in ProcArrayGroupClearXid()
Date
Msg-id CAPpHfdtxLsC-bqfxFcHswZ91OxXcZVNDBBVfg9tAWU0jvn1tQA@mail.gmail.com
Whole thread Raw
Responses Re: pg_atomic_exchange_u32() in ProcArrayGroupClearXid()  (Amit Kapila <amit.kapila16@gmail.com>)
List 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

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: proposal: prefix function
Next
From: Sergei Kornilov
Date:
Subject: Re: pgsql: Improve autovacuum logging for aggressive and anti-wraparound ru