Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
孙世龙 sunshilong
sunshilong369@gmail.com
Thu Sep 3 01:33:25 GMT 2020
Hi,
Thank you for your reply.
Yes, I am asking for a call performing busy wait.
>Resolution will vary depending on the underlying implementation e.g.
>vDSO vs. syscall.
How to verify which kind of underlying implementation is used by
certain API(e.g. clock_gettime) on a specific platform?
Thank you for your attention to this matter.
Best regards
Sunshilong
On Wed, Sep 2, 2020 at 11:38 PM Carlos O'Donell via Libc-help
<libc-help@sourceware.org> wrote:
>
> On 9/2/20 5:09 AM, Mirko Banchi via Libc-help wrote:
> > nanosleep() should suspend the thread, i think he asking for a call
> > performing busy wait.
>
> That is how I interpreted the request also.
>
> We do not have any busy-wait-semantic wait functions with timeout.
>
> The C library need not provide *all* utility functions, but must provide
> enough utility to create those functions for yourself.
>
> You can write such a function yourself using the various clock_* APIs
> to get time, busy wait, and then get the time again.
>
> Resolution will vary depending on the underlying implementation e.g.
> vDSO vs. syscall.
>
> We actually have need for this in pthread_rwlock_tryrdlock to implement
> a randomized exponential back-off to avoid live-locking (not yet done).
>
> There are valid use cases for busy-waiting, particularly when the wait
> period is so short that you don't want to yield the thread.
>
> --
> Cheers,
> Carlos.
>
More information about the Libc-help
mailing list