From: | Steve Senior <ssenior45(at)googlemail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | User timeouts for scheduling functions |
Date: | 2025-06-10 08:24:14 |
Message-ID: | B0344A8C-9D4A-4838-B362-52BCB1CFE928@googlemail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I'm prototyping an extension in which I need to execute a C function repeatedly on a timer as part of a sql execution hook, and end it when I choose.
I've spent the time reading these lists, the documentation etc and the only solution I saw that wouldn't require a patch was user-definable timeouts https://github.com/postgres/postgres/blob/master/src/include/utils/timeout.h#L40 <https://github.com/postgres/postgres/blob/master/src/include/utils/timeout.h#L40>.
I have a working implementation that at a high level does the following
/* register and enable the timeout to call my_handler_proc every second */
tId = RegisterTimeout(USER_TIMEOUT, my_handler_proc);
enable_timeout_after((int)tId, 1000);
...
/* stop the timeout */
disable_timeout((int)tId, 0);
Note: I'm also working on the code to ensure I don't try to allocate beyond MAX_TIMEOUTS but I haven't shown that here for brevity.
My question really is: should I be doing this? Is it safe? I can't find this documented nor any other examples of code that uses this which is a red flag for me.
Thanks in advance,
Steve.
From | Date | Subject | |
---|---|---|---|
Next Message | Потапов Александр | 2025-06-10 08:56:58 | Re: Init connection time grows quadratically |
Previous Message | Arseniy Mukhin | 2025-06-10 08:18:42 | Re: Amcheck verification of GiST and GIN |