Re: Avoiding roundoff error in pg_sleep()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Avoiding roundoff error in pg_sleep()
Date: 2025-09-25 21:05:45
Message-ID: 3942055.1758834345@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nathan Bossart <nathandbossart(at)gmail(dot)com> writes:
> Agreed, I'm not too worried about the system calls in this case. I think I
> was more interested in seeing whether we could avoid the complicated float
> handling. Something else that seems to work is moving the initial endtime
> calculation to within the loop, like so:

> - delay = endtime - GetNowFloat();
> + if (first)
> + {
> + endtime = GetNowFloat() + secs;
> + delay = secs;
> + first = false;
> + }
> + else
> + delay = endtime - GetNowFloat();

Hmm ... I'm not sure I'd trust that to give the right answer
if WaitLatch is interrupted so that we have to recalculate
the delay.

> But, in any case, your patch still LGTM.

Pushed it. Again, thanks for reviewing!

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2025-09-25 21:13:31 Re: Optimize LISTEN/NOTIFY
Previous Message Matheus Alcantara 2025-09-25 21:01:40 Remove unused parameter on check_and_push_window_quals