condition variable - why calling pthread_cond_signal() before calling pthread_cond_wait() is a logical error?

前端 未结 5 1165
星月不相逢
星月不相逢 2020-11-27 17:25

It\'s written in POSIX threads tutorial https://computing.llnl.gov/tutorials/pthreads/ that it is a logical error.

my question is why it is a logical error?

5条回答
  •  孤独总比滥情好
    2020-11-27 17:47

    I write my answer because I do not see the one that will calm people. I also stumbled upon that bizarre disturbing warning about “logical error” in that tutorial. Note that there is nothing about this “error” in the POSIX documentation article on pthread_cond_signal. I am sure that this is an unfortunate choice of the term or a plain mistake on part of the author of the tutorial. Their claim may be interpreted as if a process will terminate with an error in this situation or that any program permitting this situation is incorrect. Nothing of the sort is true. Such situations are common. The documentation says that

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

    So don't worry and be happy.

提交回复
热议问题