pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Nathan Bossart <nathandbossart@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: Restart pg_usleep when interrupted
Date: Thu, 11 Jul 2024 14:56:44 -0500
Message-ID: <ZpA4_Pw14FCP6025@nathan> (raw )
In-Reply-To: <2F781744-69B8-4BC2-A6EF-3998DCCDB634@gmail.com >
References: <7D50DC5B-80C6-47B5-8DA8-A6C68A115EE5@gmail.com >
<2100439.1719610468@sss.pgh.pa.us >
<AC328D21-21D6-4FFC-8F6B-BFE9AD940524@gmail.com >
<ZoPC5IeP4k7sZpki@ip-10-97-1-34.eu-west-3.compute.internal >
<373D199B-2312-431D-8018-F2808913F979@gmail.com >
<Zo0UdeE3i9d0Wt5E@ip-10-97-1-34.eu-west-3.compute.internal >
<3712E898-03DA-4E03-AF51-D3E24DE68216@gmail.com >
<C18017A1-EDFD-4F2F-BCA1-0572D4CCC92B@gmail.com >
<Zo_7blmO166ZDGbW@nathan >
<2F781744-69B8-4BC2-A6EF-3998DCCDB634@gmail.com >
On Thu, Jul 11, 2024 at 01:10:25PM -0500, Sami Imseih wrote:
>> I'm curious why we wouldn't just subtract "elapsed_time" from "delay" at
>> the bottom of the while loop to avoid needing this extra check.
>
> Can you elaborate further? I am not sure how this will work since delay is a timespec
> and elapsed time is an instr_time.
>
> Also, in every iteration of the loop, the delay must be set to the remaining time. The
> purpose of the elapsed_time is to make sure that we don“t surpass requested time
> delay as an additional safeguard.
I'm imagining something like this:
struct timespec delay;
TimestampTz end_time;
end_time = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), msec);
do
{
long secs;
int microsecs;
TimestampDifference(GetCurrentTimestamp(), end_time,
&secs, µsecs);
delay.tv_sec = secs;
delay.tv_nsec = microsecs * 1000;
} while (nanosleep(&delay, NULL) == -1 && errno == EINTR);
--
nathan
view thread (73+ messages) latest in thread
Message-ID: <ZpA4_Pw14FCP6025@nathan>
Permalink: ../ZpA4_Pw14FCP6025@nathan/
Also on: postgresql.org/message-id/ZpA4_Pw14FCP6025@nathan
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, samimseih@gmail.com, bertranddrouvot.pg@gmail.com, tgl@sss.pgh.pa.us, robertmhaas@gmail.com
Subject: Re: Restart pg_usleep when interrupted
In-Reply-To: <ZpA4_Pw14FCP6025@nathan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox