Re: Is this non-volatile pointer access OK?

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Is this non-volatile pointer access OK?
Дата
Msg-id 1346721671.30124.7.camel@vanquo.pezone.net
обсуждение исходный текст
Ответ на Re: Is this non-volatile pointer access OK?  (Peter Geoghegan <peter@2ndquadrant.com>)
Список pgsql-hackers
On Mon, 2012-09-03 at 11:14 +0100, Peter Geoghegan wrote:
> Come to think of it, the whole convention of using a lower-case
> variant of the original pointer variable name seems like a foot-gun,
> given the harmful and indeed very subtle consequences of making this
> error.

With some inventive macro magic, you could probably make this safer.
I'm thinking something along the lines of replacing

SpinLockAcquire(&xlogctl->info_lck);

with

SpinLockAcquire(XLogCtl, info_lck);

which expands to

{   volatile typeof(XLogCtl) *XLogCtl_volatile = XLogCtl;   void *XLogCtl = NULL;  // compiler error or crash at run
timeif used   OldSpinLockAcquire(XLogCtl_volatile->info_lock);   ...
 

and then something corresponding for SpinLockRelease.

This will likely only work with modern compilers, but it could give you
some amount of static checking against this problem.





В списке pgsql-hackers по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Cascading replication and recovery_target_timeline='latest'
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Yet another failure mode in pg_upgrade