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 10:34:06 -0500
Message-ID: <Zo_7blmO166ZDGbW@nathan> (raw)
In-Reply-To: <C18017A1-EDFD-4F2F-BCA1-0572D4CCC92B@gmail.com>
References: <01000190606e3d2a-116ead16-84d2-4449-8d18-5053da66b1f4-000000@email.amazonses.com>
	<CA+TgmobMqV95Zj2906s4_dtS2_JKqG-6ogKHGdiH+y3rar9NCA@mail.gmail.com>
	<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>

+		/*
+		 * We allow nanosleep to handle interrupts and retry with the remaining time.
+		 * However, since nanosleep is susceptible to time drift when interrupted
+		 * frequently, we add a safeguard to break out of the nanosleep whenever the
+		 * total time of the sleep exceeds the requested sleep time. Using nanosleep
+		 * is a more portable approach than clock_nanosleep.
+		 */

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.  Also, I
think we need some commentary about why we want to retry after an interrupt
in this case.

-- 
nathan





view thread (73+ messages)  latest in thread

Message-ID: <Zo_7blmO166ZDGbW@nathan>
Permalink:  ../Zo_7blmO166ZDGbW@nathan/
Also on:    postgresql.org/message-id/Zo_7blmO166ZDGbW@nathan

 · 

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: <Zo_7blmO166ZDGbW@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