Re: Use nanosleep() for pg_usleep() on Unix/Linux? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Use nanosleep() for pg_usleep() on Unix/Linux?
Date
Msg-id 24848.1473607575@sss.pgh.pa.us
Whole thread Raw
In response to Use nanosleep() for pg_usleep() on Unix/Linux?  (Paul Guo <paulguo@gmail.com>)
List pgsql-hackers
Paul Guo <paulguo@gmail.com> writes:
> I happened to read the pg_usleep() code recently. I'm wondering
> if we could implement it using the posix function nanosleep(),
> instead of by select().

That actually looks like a pretty good idea.  Some research says that
nanosleep() is defined in SUSv2, our usual baseline for Unix features;
and it appears to be implemented and work per spec on even my oldest
buildfarm critters.  So portability looks like a non problem.

It would be nice to have two versions of pg_usleep, one where handling
of a signal was guaranteed to terminate the wait and one where it was
guaranteed not to, rather than the current no-promises situation.
It looks like we could have that on the Unix side using nanosleep(),
but it's not clear to me whether we can do the second case on Windows.

> nanosleep() is designed with higher time resolution, besides it provide
> remaining time if is interrupted by signal so that pg_usleep() could
> be implemented more accurately.
> or combine with clock_gettime() to control the sleep time more accurately.

I do not think we really care about sub-microsecond sleep resolution.
But it would be good if we could implement a sleep that would be
approximately the requested length even with signals received meanwhile.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH] Alter or rename enum value
Next
From: Heikki Linnakangas
Date:
Subject: Re: Tuplesort merge pre-reading