Re: pgsql: Do all accesses to shared buffer headers through

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Do all accesses to shared buffer headers through
Date: 2005-10-12 22:54:29
Message-ID: 4966.1129157669@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Neil Conway <neilc(at)samurai(dot)com> writes:
> On Wed, 2005-12-10 at 13:45 -0300, Tom Lane wrote:
>> Do all accesses to shared buffer headers through volatile-qualified
>> pointers, to ensure that compilers won't rearrange accesses to occur
>> while we're not holding the buffer header spinlock.

> That is fairly error prone :-( Would it be possible to hide this in a
> typedef?

How would a typedef make it safer? I see no particular difference
between omitting the "volatile" and choosing the wrong typedef.
Neither will happen if you follow the coding style of surrounding
routines (which is one reason I chose to make *all* the bufmgr routines
declare BufferDesc pointers as volatile, even though some of them
arguably didn't need to). If you don't follow the coding style,
neither convention will catch you at it.

We do however have here a New Coding Rule that's good for all parts
of the backend: if you are accessing a spinlock-protected data structure
then you should be using a volatile-qualified pointer for it. I had
at one time thought that volatile-qualifying the spinlock pointer should
be enough, on the grounds that compilers shouldn't move other stores
across a store to volatile. But apparently gcc only promises not to
rearrange volatile stores with respect to each other.

regards, tom lane

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2005-10-12 23:19:23 pgsql: Fix spelling error, per Michael Fuhr.
Previous Message Neil Conway 2005-10-12 22:41:42 Re: pgsql: Do all accesses to shared buffer headers

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-10-12 23:06:01 Re: How TODO prevent PQfnumber() from lowercasing?
Previous Message Neil Conway 2005-10-12 22:41:42 Re: pgsql: Do all accesses to shared buffer headers