From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Stephen Woodbridge <woodbri(at)swoodbridge(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to check for pending CancelRequest from C/C++ function |
Date: | 2014-01-06 17:25:37 |
Message-ID: | 6168.1389029137@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Stephen Woodbridge <woodbri(at)swoodbridge(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2014-01-06 17:48:35 | Re: returning json data row from json query |
Previous Message | Adrian Klaver | 2014-01-06 17:05:01 | Re: WAL archive cleanup om master |