Pthread的 - 什么是睡眠()和pthreads.h中:: pthread_yield()time.h中的区别::? [英] Pthread - What is the difference between time.h::sleep() and pthread.h::pthread_yield()?

查看:2154
本文介绍了Pthread的 - 什么是睡眠()和pthreads.h中:: pthread_yield()time.h中的区别::?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了好长一段时间寻找有关time.h中::睡眠()和pthreads.h中:: pthread_yield()之间的差异信息,但无法找到任何可靠的参考材料等我张贴了这个问题。

I spent a good long while looking for info on the differences between time.h::sleep() and pthread.h::pthread_yield() but was unable to find any solid reference material and so I am posting this question.

什么是睡眠()和pthreads.h中:: pthread_yield()?

What is the difference between time.h::sleep() and pthread.h::pthread_yield()?

更新:

我想问的原因是因为我用睡眠()睡眠()每个线程...和我的应用程序开始有问题时,有8个线程对4线程。当我去网上看看睡眠()只影响每个线程,我找不到任何很好的参考,说明睡眠()是否会影响整个进程或睡眠()仅影响单个线程。

The reason I ask is because I was using sleep() to sleep() each individual thread... and my application started having issues when there was 8 threads vs 4 threads. When I went online to see if sleep() only affects each thread, I couldn't find any good reference stating whether Sleep() affects the entire process OR sleep() only affects the individual thread.

推荐答案

从<一个href=\"http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread%5Fyield.htm\">pthread_yield:

该pthread_yield例程强制调用线程放弃其使用的处理器,它再次定前的运行队列中等待。如果运行队列为空时,pthread_yield子程序调用,调用线程立即重新安排。

The pthread_yield subroutine forces the calling thread to relinquish use of its processor, and to wait in the run queue before it is scheduled again. If the run queue is empty when the pthread_yield subroutine is called, the calling thread is immediately rescheduled.

睡眠手册页

睡眠()使调用进程休眠状态,直到秒秒经过或信号到达这也是不可忽视的。

sleep() makes the calling process sleep until seconds seconds have elapsed or a signal arrives which is not ignored.

如果你不想在你的线程实时延迟,只是希望允许其他线程做好自己的工作,那么pthread_yield更适合比睡眠。

If you don't want to have a real time delay in your threads and just want to allow other threads to do their work, then pthread_yield is better suited than sleep.

这篇关于Pthread的 - 什么是睡眠()和pthreads.h中:: pthread_yield()time.h中的区别::?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆