Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3lKI-0001rv-CQ for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2019 17:36:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3lKF-0001gm-VQ for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2019 17:36:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3lKF-0001gf-NV for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2019 17:36:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3lKD-0004Gf-AI for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2019 17:36:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x2CHaLrI009876; Tue, 12 Mar 2019 13:36:21 -0400 From: Tom Lane To: Robert Haas cc: PostgreSQL Hackers Subject: Re: Use nanosleep(2) in pg_usleep, if available? In-reply-to: References: <4902.1552349020@sss.pgh.pa.us> <9173.1552410822@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Tue, 12 Mar 2019 13:17:19 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9874.1552412181.1@sss.pgh.pa.us> Date: Tue, 12 Mar 2019 13:36:21 -0400 Message-ID: <9875.1552412181@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > On Tue, Mar 12, 2019 at 1:13 PM Tom Lane wrote: >> (I'm not sure what I think about which behavior is really more >> desirable. We can debate that if there's actually a plausible >> choice to be made, which seems to depend on Windows.) > Yeah, that's a fair question. My motivation for asking was that I > sometimes try to insert sleeps when debugging things, and they don't > actually sleep, because they get interrupted. That's not dispositive, > though. There never has been a guarantee that we won't sleep for *more* than the requested time; the kernel might not give us back the CPU right away. But re-sleeping would at least ensure that we won't sleep for *less* than the requested time. So my opinion after five minutes' thought is that re-sleeping is better, because it gives you at least some kind of promise related to the function's nominal semantics. It still depends on whether we can make Windows do it, though. I suppose a brute-force way would be like what WaitLatch does: do our own timekeeping using instr_time.h. (That'd work for select as well, I guess.) regards, tom lane