线程让出实验【RT-Thread学习笔记 4】
API: rt_thread_yield
线程函数中调用,本线程释放MCU。如果此时有别的相同优先级的任务整处于等待状态,将获得MCU使用权。
线程让出就是给OS增加一个任务调度的机会。
创建两个线程,观察他们的结果:
//线程让出试验
void yield_test1(void* parameter)
{
rt_uint32_t count = 0;
while(1)
{
rt_kprintf("thread test1 count:%d\n",count++);
rt_thread_yield();
}
}
void yield_test2(void* parameter)
{
rt_uint32_t count = 0;
while(1)
{
rt_kprintf("thread test2 count:%d\n",count++);
rt_thread_yield();
}
}
启动他们:
//线程让出实验,两个线程优先级一样。否则在给一次调度机会也是高优先级的任务使用MCU
tid2 = rt_thread_create("yield1",yield_test1,RT_NULL,2048,10,5);
if(tid2 != RT_NULL)
rt_thread_startup(tid2);
tid2 = rt_thread_create("yield2",yield_test2,RT_NULL,2048,10,5);
if(tid2 != RT_NULL)
rt_thread_startup(tid2);
看见两个线程轮流输出:
\ | /
- RT - Thread Operating System
/ | \ 2.0.0 build Aug 29 2014
2006 - 2013 Copyright by rt-thread team
thread test1 count:0
thread test2 count:0
thread test1 count:1
thread test2 count:1
thread test1 count:2
thread test2 count:2
thread test1 count:3
thread test2 count:3
thread test1 count:4
thread test2 count:4
thread test1 count:5
thread test2 count:5
……..
如果没有线程让出的操作,情况将是等一个线程时间片结束之后,才会轮到另一个线程输出。不会是轮流输出了
线程让出实验【RT-Thread学习笔记 4】的更多相关文章
- JavaSE中线程与并行API框架学习笔记——线程为什么会不安全?
前言:休整一个多月之后,终于开始投简历了.这段时间休息了一阵子,又病了几天,真正用来复习准备的时间其实并不多.说实话,心里不是非常有底气. 这可能是学生时代遗留的思维惯性--总想着做好万全准备才去做事 ...
- 线程优先级抢占实验【RT-Thread学习笔记 3】
同时处于就绪状态的线程,优先级高的先执行. 高优先级就绪时,低优先级任务让出CPU,让高优先级任务先执行. 创建两个任务函数: //线程优先级抢占 void thread1_entry(void *p ...
- JavaSE中线程与并行API框架学习笔记1——线程是什么?
前言:虽然工作了三年,但是几乎没有使用到多线程之类的内容.这其实是工作与学习的矛盾.我们在公司上班,很多时候都只是在处理业务代码,很少接触底层技术. 可是你不可能一辈子都写业务代码,而且跳槽之后新单位 ...
- Boost Thread学习笔记
thread自然是boost::thread库的主 角,但thread类的实现总体上是比较简单的,前面已经说过,thread只是一个跨平台的线程封装库,其中按照所使用的编译选项的不同,分别决定使用 W ...
- thread学习笔记--BackgroundWorker 类
背景: 在 WinForms 中,有时要执行耗时的操作,比如统计某个磁盘分区的文件夹或者文件数目,如果分区很大或者文件过多的话,处理不好就会造成“假死”的情况,或者报“线程间操作无效”的异常,或者在该 ...
- Boost Thread学习笔记五
多线程编程中还有一个重要的概念:Thread Local Store(TLS,线程局部存储),在boost中,TLS也被称作TSS,Thread Specific Storage.boost::thr ...
- Boost Thread学习笔记四
barrierbarrier类的接口定义如下: 1 class barrier : private boost::noncopyable // Exposition only 2 { 3 pub ...
- Boost Thread学习笔记三
下面先对condition_impl进行简要分析.condition_impl在其构造函数中会创建两个Semaphore(信号量):m_gate.m_queue,及一个Mutex(互斥体,跟boost ...
- Boost Thread学习笔记二
除了thread,boost种:boost::mutexboost::try_mutexboost::timed_mutexboost::recursive_mutexboost::recursive ...
随机推荐
- BackTrack5-r3改源
默认源服务器是国外的,更新起来会很慢,所以要改成国内的. 所需要的文件包地址:http://pan.baidu.com/s/1i3ouc9v(64位更新包)进入BT系统图形模式-将(语言选择器)文件拖 ...
- 黑马----JAVA比较器:Comparable和Comparator
黑马程序员:Java培训.Android培训.iOS培训..Net培训 一.Comparable接口 1.public interface Comparable{ public int compare ...
- Android上传图片到服务器
一.android需要导入异步请求的jar包 AsyncHttpClient public static void reg(final Context cont,Bitmap photodata,S ...
- android view:手势
一直认为android手势识别很是神奇,我们不分析复杂的手势,仅仅是针对上一次的基本事件的手势处理,分析GestureDetector的源码,来看一下到底手势事件是如何定义的. GestureDete ...
- 特殊的对象引用---$this
只要是对象中的成员,必须使用这个对象($this)来访问到这个对象内部的属性和方法 特殊对象的引用$this就是再对象内部的成员方法中,代表本对象的一个引用,但智能在对象的成员方法中使用,不管是在对象 ...
- tableView优化性能
在iOS应用中,UITableView应该是使用率最高的视图之一了.iPod.时钟.日历.备忘录.Mail.天气.照片.电话.短信. Safari.App Store.iTunes.Game Cent ...
- HTML DOM 节点
一切皆节点 在 HTML DOM (文档对象模型)中,节点主要包括(括号中用数字表示节点类型):元素(1).属性(2).文本(3,其中换行符也是一个文本节点).注释(8).文档(9). 其中重要的方法 ...
- Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- PullToRefreshGridView刷新加载
<com.handmark.pulltorefresh.library.PullToRefreshGridView xmlns:ptr="http://schemas.a ...
- Ionic2学习笔记
Component nav: <ion-nav [root] = 'rootComponent'></ion-nav> ....import {Nav} from 'ionic ...