gpt4 book ai didi

multithreading - 多个线程可以同时等待一个信号量

转载 作者:行者123 更新时间:2023-12-03 12:52:37 26 4
gpt4 key购买 nike

多个线程可以在一个信号量上等待吗?
如果是,则在信号量下降时将恢复哪一个?

最佳答案

正如sem_postdocument所暗示的那样,

If the value of the semaphore resulting from this operation is zero, then one of the threads blocked waiting for the semaphore will be allowed to return successfully from its call to sem_wait(). If the symbol _POSIX_PRIORITY_SCHEDULING is defined, the thread to be unblocked will be chosen in a manner appropriate to the scheduling policies and parameters in effect for the blocked threads. In the case of the schedulers SCHED_FIFO and SCHED_RR, the highest priority waiting thread will be unblocked, and if there is more than one highest priority thread blocked waiting for the semaphore, then the highest priority thread that has been waiting the longest will be unblocked. If the symbol _POSIX_PRIORITY_SCHEDULING is not defined, the choice of a thread to unblock is unspecified.



另外,正如 sem_wait 在“应用程序使用情况”部分中定义的那样,可能存在优先级反转的情况,涉及优先级不同的线程

关于multithreading - 多个线程可以同时等待一个信号量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16163932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com