[PATCH v2] tests: posix: use cpu clock for sleep
Yury Khrustalev
yury.khrustalev@arm.com
Wed Feb 18 09:51:06 GMT 2026
On Tue, Feb 17, 2026 at 01:09:56PM -0500, DJ Delorie wrote:
> Yury Khrustalev <yury.khrustalev@arm.com> writes:
> > so I don't see what's wrong here. Please elaborate.
>
> Perhaps I'm miscommunicating.
>
> I don't care which clock you use to determine if 2 seconds has passed.
>
> I'm looking at these lines:
>
> + while (ts.tv_sec < end || (ts.tv_sec == end && ts.tv_nsec < end_ns))
> + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts);
>
> This is a busy-wait loop. It would be better on most platforms to do
> *something* to pause the program, even if only a little. Example:
>
> + while (ts.tv_sec < end || (ts.tv_sec == end && ts.tv_nsec < end_ns))
> + {
> + sleep(1);
> + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts);
> + }
I see, thanks for clarification!
>
> On your target, the sleep() would do nothing,
The problem is that it doesn't to nothing exactly: it advances "time" by
whatever delta we're waiting for but does so instantly so the current
thread continues but its perception of the result of time() has changed
in a "correct" way.
If busy waiting is not ideal, then I guess I have to keep this patch
downstream. Let me think more about this.
More information about the Libc-alpha
mailing list