[PATCH v2] tests: posix: use cpu clock for sleep
Yury Khrustalev
yury.khrustalev@arm.com
Wed Feb 18 12:55:19 GMT 2026
On Wed, Feb 18, 2026 at 09:51:06AM +0000, Yury Khrustalev wrote:
> 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.
> > ...
> >
> > 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);
> > + }
Also, CLOCK_PROCESS_CPUTIME_ID time does not increase when the process
sleeps (i.e. does not consume CPU time).
More information about the Libc-alpha
mailing list