睡眠方法和多线程的屈服方法有什么区别? [英] what is difference between sleep method and yield method of multi threading?

查看:105
本文介绍了睡眠方法和多线程的屈服方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当遇到调用 [sleep] [1](); 时正在执行线程,然后线程立即进入休眠状态
,其中 [yield] [2](); 线程进入可运行状态/就绪状态

As currently executing thread while it encounters the call [sleep][1](); then thread moves immediately into sleeping state where as for [yield][2](); thread moves into runnable state/ready state

推荐答案

sleep()导致线程在给定的时间内明确停止执行;如果不需要运行其他线程或进程,CPU将处于空闲状态(并可能进入省电模式)。

sleep() causes the thread to definitely stop executing for a given amount of time; if no other thread or process needs to be run, the CPU will be idle (and probably enter a power saving mode).

yield() 基本上意味着线程没有做任何特别重要的事情,如果需要运行任何其他线程或进程,它们应该。否则,当前线程将继续运行。

yield() basically means that the thread is not doing anything particularly important and if any other threads or processes need to be run, they should. Otherwise, the current thread will continue to run.

这篇关于睡眠方法和多线程的屈服方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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