Re: Use nanosleep() for pg_usleep() on Unix/Linux?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Use nanosleep() for pg_usleep() on Unix/Linux?
Дата
Msg-id 24848.1473607575@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Use nanosleep() for pg_usleep() on Unix/Linux?  (Paul Guo <paulguo@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [PATCH] Alter or rename enum value
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Tuplesort merge pre-reading