What happens if no threads are waiting and condition signal was sent?

我怕爱的太早我们不能终老 提交于 2020-01-04 04:23:06

问题


What happens if all threads are busy and main thread has sent thread cond signal ?

1 Main Thread and 3 pthreads in thread pool. 3 pthreads are in status of

    pthread_mutex_lock(&sync_mutex);
    pthread_cond_wait(&sync_cond, &sync_mutex);
    pthread_mutex_unlock(&sync_mutex);

Main thread has sent Signal to wake up the threads to process the work. In this situation, What if 3 threads are already busy and next signal has arrived?


回答1:


Nothing. The signal disappears.




回答2:


If your using one of the following functions:

pthread_cond_signal - restarts one of the threads that are waiting on the condition variable cond. pthread_cond_broadcast - wake up all threads blocked by the specified condition variable.

The manual states that

The pthread_cond_broadcast() and pthread_cond_signal() functions shall have no effect if there are no threads currently blocked on cond.



来源:https://stackoverflow.com/questions/9598034/what-happens-if-no-threads-are-waiting-and-condition-signal-was-sent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!