gpt4 book ai didi

c - 函数 pthread_yield 是如何工作的?

转载 作者:行者123 更新时间:2023-12-05 02:46:39 25 4
gpt4 key购买 nike

我正在用 C 语言实现一个线程库,但我对 pthread_yield() 的含义深信不疑。我在 man page 上查过了在终端,但我并不真正理解解释。谁能给我解释一下?

最佳答案

请注意,尽管它的名称如此,pthread_yield 并未标准化。 Its Linux manual page例如这样说:

This call is nonstandard, but present on several other systems. Use the standardized sched_yield(2) instead.

The specifications for sched_yield()pthread_yield() 的术语几乎相同,但是:

The sched_yield() function shall force the running thread to relinquish the processor until it again becomes the head of its thread list. It takes no arguments.

这只是意味着调用该函数的线程允许其他线程和进程有机会运行,等待恢复直到再次轮到它。在诸如 pthreads 之类的抢占式多任务系统中,没有必要这样做——内核在没有任何此类帮助的情况下管理将 CPU 时间分配给线程和进程——但偶尔可能会出现特殊情况,它可以解决线程调度问题.

关于c - 函数 pthread_yield 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65380997/

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