c - pthread_cond_signal 和可能的线程饥饿

标签 c linux pthreads

如果多个线程等待条件变量,则 pthread_cond_signal 唤醒的顺序是什么。我读过 pthread_cond_signal 不一定按 sleep 顺序唤醒。所以这可能会导致饥饿......不是吗?

谢谢

最佳答案

它是由调度策略决定的,应该是公平的。

如果线程没有因调度而饥饿 - 它们也不应该因此而饥饿。

来自spec :

If more than one thread is blocked on a condition variable, the scheduling policy determines the order in which threads are unblocked.

关于c - pthread_cond_signal 和可能的线程饥饿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6401474/

相关文章:

c - 将命令行字符串作为单独的字符添加到数组

linux - 在 Linux 上的 gphoto2 中连拍拍摄照片

c - pthread 在使用虚拟核心时没有提供性能提升

c - SO_TIMESTAMP 套接字选项使用哪个时钟?

linux - linux内核中指令{interrupt do_IRQ}是什么意思?

c - libc 源位置 - 用于下载或在线查看?

c - 没有全局变量的 pthreads 互斥锁,只返回 thread_struct 中的数组

交叉编译可执行文件无法解析符号 pthread_create

c - malloc->分配了多少内存?

c - 将 C 结构包装到 Ruby