pthread_cond_timedwait and usleep difference

526 Views Asked by At

I want my thread wait for some microseconds and currently using usleep for that purpose. I recently noticed pthread_cond_timedwait function which is also used for letting the application wait for sometime. Do you know which is better in terms of waiting time accuracy?

1

There are 1 best solutions below

0
On

Just from the name you can guess that pthread_cond_timedwait is conditional, that is to say, if the condition meets, the wait will return immediately.

But, if you intentionally make the condition to be false forever, then pthread_cond_timedwait might have the same effect as usleep.

The accuracy should be the same.