cpthreadsinternalsbusy-waiting

Is pthreads doing busy waiting internally?


I would like to know if pthreads is doing busy waiting internally when calling pthread_cond_timedwait()?

I'm analysing a multi-threaded program and need to know if a thread is potentially blocking ressources when calling the above function.

Platform: Intel x86_64, CentOS 7.5.1804 with GCC 5.3.0


Solution

  • As you will have read in their documentation, the pthread_cond_wait() and pthread_cond_timedwait() functions cause the calling thread to block until the CV is signaled, or, in the latter case, the specified time arrives. (Or the thread is cancelled, or it is temporarily aroused to handle a signal, or ....) Blocking does not merely mean that the thread does not return from the function. It means that the thread is not scheduled on any execution unit as long as it remains blocked. Thus, no, threads blocked in pthread_cond_timedwait() do not busy-wait.