Re: How to check for pending CancelRequest from C/C++ function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to check for pending CancelRequest from C/C++ function
Дата
Msg-id 6168.1389029137@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How to check for pending CancelRequest from C/C++ function  (Stephen Woodbridge <woodbri@swoodbridge.com>)
Список pgsql-general
Stephen Woodbridge <woodbri@swoodbridge.com> writes:
> On 1/6/2014 10:32 AM, Tom Lane wrote:
>> Put "CHECK_FOR_INTERRUPTS();" in some suitably safe place.

> So if I need to clean up then I should check do something like:

> if (InterruptPending) {
>      /* cleanup here */
>      ProcessInterrupts();
> }

Uh, no, you should just do "CHECK_FOR_INTERRUPTS();", because that's
all that's going to happen if any subroutine you happen to call chooses
to check for query cancel.  Or more generally, any sort of error is
going to take control away from you.

If you have cleanup that has to happen, you need to arrange for that
to happen during transaction or subtransaction abort.  In most cases
there is infrastructure that can help you with this, but if you're
dealing with some resource not known to PG core code then you might
have to resort to a transaction-end callback function or something
like that.

Depending on how localized the cleanup requirement is, you might
be able to use a PG_TRY/PG_CATCH block to enforce cleanup when an
error is thrown.

> Similarly if I'm in C++ code I can probably include miscadmin.h as an
> extern C to get access to this.

One of the main problems with using C++ for PG extensions is that
its exception infrastructure doesn't play nice with the longjmps
underlying PG error processing.  You can create interface code to
translate between the two conventions, but it's notationally tedious.

            regards, tom lane


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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: WAL archive cleanup om master
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: returning json data row from json query