日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

线程让出实验【RT-Thread学习笔记 4】

發(fā)布時(shí)間:2023/12/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 线程让出实验【RT-Thread学习笔记 4】 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

API: rt_thread_yield

線程函數(shù)中調(diào)用,本線程釋放MCU。如果此時(shí)有別的相同優(yōu)先級(jí)的任務(wù)整處于等待狀態(tài),將獲得MCU使用權(quán)。

線程讓出就是給OS增加一個(gè)任務(wù)調(diào)度的機(jī)會(huì)。

創(chuàng)建兩個(gè)線程,觀察他們的結(jié)果:

//線程讓出試驗(yàn) 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();} }

啟動(dòng)他們:

//線程讓出實(shí)驗(yàn),兩個(gè)線程優(yōu)先級(jí)一樣。否則在給一次調(diào)度機(jī)會(huì)也是高優(yōu)先級(jí)的任務(wù)使用MCUtid2 = 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);?

看見兩個(gè)線程輪流輸出:

\ | /

- 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

……..

如果沒有線程讓出的操作,情況將是等一個(gè)線程時(shí)間片結(jié)束之后,才會(huì)輪到另一個(gè)線程輸出。不會(huì)是輪流輸出了

總結(jié)

以上是生活随笔為你收集整理的线程让出实验【RT-Thread学习笔记 4】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。