Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stephen Woodbridge <woodbri@xxxxxxxxxxxxxxx> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux