LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 664|回复: 1

pth_yield函数是做什么的?(pth的库函数)

[复制链接]
发表于 2005-10-31 16:37:54 | 显示全部楼层 |阅读模式
以下是说明原文,看的头疼,谁给通俗点解释一下?

int pth_yield(pth_t tid);

This explicitly yields back the execution control to the scheduler thread. Usually the execution is implicitly transferred back to the scheduler when a thread waits for an event. But when a thread has to do larger CPU bursts, it can be reasonable to interrupt it explicitly by doing a few pth_yield(3) calls to give other threads a chance to execute, too. This obviously is the cooperating part of Pth. A thread has not to yield execution, of course. But when you want to program a server application with good response times the threads should be cooperative, i.e., when they should split their CPU bursts into smaller units with this call.
Usually one specifies tid as NULL to indicate to the scheduler that it can freely decide which thread to dispatch next. But if one wants to indicate to the scheduler that a particular thread should be favored on the next dispatching step, one can specify this thread explicitly. This allows the usage of the old concept of coroutines where a thread/routine switches to a particular cooperating thread. If tid is not NULL and points to a new or ready thread, it is guaranteed that this thread receives execution control on the next dispatching step. If tid is in a different state (that is, not in PTH_STATE_NEW or PTH_STATE_READY) an error is reported.

The function usually returns TRUE for success and only FALSE (with errno set to EINVAL) if tid specified an invalid or still not new or ready thread.
发表于 2005-10-31 22:12:23 | 显示全部楼层
嗯,大概的意思是:
该调用会掸让自己获得的cpu,而让其他线程执行.如果一个线程的交互性较高,则可以使用这个调用使自己每次执行的时间片变小

tid指示了下面该由哪个线程执行,若tid为null,则由内核自己选择.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表