Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
相同优先级时间片轮转调度
timeslice_sample
跑timeslice_sample的示例,运行结果与文档说明的结果不一样
发布于 2021-06-08 12:01:36 浏览:768
订阅该版
单片机型号:STM32F070RBT6 使用MDK移植,或者使用RT—Thread-studio创建工程,同样跑的timeslice_sample的示例程序,运行结果都不一样,并且与文档中心或者内核实验手册描述的结果都不一样。 代码如下 ```c #include
#define THREAD_STACK_SIZE 1024 #define THREAD_PRIORITY 20 #define THREAD_TIMESLICE 10 /* 线程入口 */ static void thread_entry(void* parameter) { rt_uint32_t value; rt_uint32_t count = 0; value = (rt_uint32_t)parameter; while (1) { if(0 == (count % 5)) { rt_kprintf("thread %d is running ,thread %d count = %d\n", value , value , count); if(count > 200) return; } count++; } } int timeslice_sample(void) { rt_thread_t tid; /* 创建线程1 */ tid = rt_thread_create("thread1", thread_entry, (void*)1, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (tid != RT_NULL) rt_thread_startup(tid); /* 创建线程2 */ tid = rt_thread_create("thread2", thread_entry, (void*)2, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE-5); if (tid != RT_NULL) rt_thread_startup(tid); return 0; } /* 导出到 msh 命令列表中 */ MSH_CMD_EXPORT(timeslice_sample, timeslice sample); ``` MDK移植运行结果如下: ``` msh >timeslice_sample thread 1 is running ,thread 1 count = 0 thread 1 is running ,thread 1 count = 5 thread 1 is running ,thread 1 count = 10 thread 1 is running ,thread 1 count = 15 thread 1 is running ,thread 1 count = 20 thread 1 is running ,thread 1 count = 25 thread 1 is running ,thread 1 count = 30 thread 1 is running ,thread 1 count = 35 thread 1 is running ,thread 1 count = 40 thread 1 is running ,thread 1 count = 45 thread 1 is running ,thread 1 count = 50 thread 1 is running ,thread 1 count = 55 thread 1 is running ,thread 1 count = 60 thread 1 is running ,thread 1 count = 65 thread 1 is running ,thread 1 count = 70 thread 1 is running ,thread 1 count = 75 thread 1 is running ,thread 1 count = 80 thread 1 is running ,thread 1 count = 85 thread 1 is running ,thread 1 count = 90 thread 1 is running ,thread 1 count = 95 thread 1 is running ,thread 1 count = 100 thread 1 is running ,thread 1 count = 105 thread 1 is running ,thread 1 count = 110 thread 1 is running ,thread 1 count = 115 thread 1 is running ,thread 1 count = 120 thread 1 is running ,thread 1 count = 125 thread 1 is running ,thread 1 count = 130 thread 1 is running ,thread 1 count = 135 thread 1 is running ,thread 1 count = 140 thread 1 is running ,thread 1 count = 145 thread 1 is running ,thread 1 count = 150 thread 1 is running ,thread 1 count = 155 thread 1 is running ,thread 1 count = 160 thread 1 is running ,thread 1 count = 165 thread 1 is running ,thread 1 count = 170 thread 1 is running ,thread 1 count = 175 thread 1 is running ,thread 1 count = 180 thread 1 is running ,thread 1 count = 185 thread 1 is running ,thread 1 count = 190 thread 1 is running ,thread 1 count = 195 thread 1 is running ,thread 1 count = 200 thread 1 is running ,thread 1 count = 205 thread 2 is running ,thread 2 count = 0 thread 2 is running ,thread 2 count = 5 thread 2 is running ,thread 2 count = 10 thread 2 is running ,thread 2 count = 15 thread 2 is running ,thread 2 count = 20 thread 2 is running ,thread 2 count = 25 thread 2 is running ,thread 2 count = 30 thread 2 is running ,thread 2 count = 35 thread 2 is running ,thread 2 count = 40 thread 2 is running ,thread 2 count = 45 thread 2 is running ,thread 2 count = 50 thread 2 is running ,thread 2 count = 55 thread 2 is running ,thread 2 count = 60 thread 2 is running ,thread 2 count = 65 thread 2 is running ,thread 2 count = 70 thread 2 is running ,thread 2 count = 75 thread 2 is running ,thread 2 count = 80 thread 2 is running ,thread 2 count = 85 thread 2 is running ,thread 2 count = 90 thread 2 is running ,thread 2 count = 95 thread 2 is running ,thread 2 count = 100 thread 2 is running ,thread 2 count = 105 thread 2 is running ,thread 2 count = 110 thread 2 is running ,thread 2 count = 115 thread 2 is running ,thread 2 count = 120 thread 2 is running ,thread 2 count = 125 thread 2 is running ,thread 2 count = 130 thread 2 is running ,thread 2 count = 135 thread 2 is running ,thread 2 count = 140 thread 2 is running ,thread 2 count = 145 thread 2 is running ,thread 2 count = 150 thread 2 is running ,thread 2 count = 155 thread 2 is running ,thread 2 count = 160 thread 2 is running ,thread 2 count = 165 thread 2 is running ,thread 2 count = 170 thread 2 is running ,thread 2 count = 175 thread 2 is running ,thread 2 count = 180 thread 2 is running ,thread 2 count = 185 thread 2 is running ,thread 2 count = 190 thread 2 is running ,thread 2 count = 195 thread 2 is running ,thread 2 count = 200 thread 2 is running ,thread 2 count = 205 msh >timeslice_sample thread 1 is running ,thread 1 count = 0 thread 1 is running ,thread 1 count = 5 thread 1 is running ,thread 1 count = 10 thread 1 is running ,thread 1 count = 15 thread 1 is running ,thread 1 count = 20 thread 1 is running ,thread 1 count = 25 thread 1 is running ,thread 1 count = 30 thread 1 is running ,thread 1 count = 35 thread 1 is running ,thread 1 count = 40 thread 1 is running ,thread 1 count = 45 thread 1 is running ,thread 1 count = 50 thread 1 is running ,thread 1 count = 55 thread 1 is running ,thread 1 count = 60 thread 1 is running ,thread 1 count = 65 thread 1 is running ,thread 1 count = 70 thread 1 is running ,thread 1 count = 75 thread 1 is running ,thread 1 count = 80 thread 1 is running ,thread 1 count = 85 thread 1 is running ,thread 1 count = 90 thread 1 is running ,thread 1 count = 95 thread 1 is running ,thread 1 count = 100 thread 1 is running ,thread 1 count = 105 thread 1 is running ,thread 1 count = 110 thread 1 is running ,thread 1 count = 115 thread 1 is running ,thread 1 count = 120 thread 1 is running ,thread 1 count = 125 thread 1 is running ,thread 1 count = 130 thread 1 is running ,thread 1 count = 135 thread 1 is running ,thread 1 count = 140 thread 1 is running ,thread 1 count = 145 thread 1 is running ,thread 1 count = 150 thread 1 is running ,thread 1 count = 155 thread 1 is running ,thread 1 count = 160 thread 1 is running ,thread 1 count = 165 thread 1 is running ,thread 1 count = 170 thread 1 is running ,thread 1 count = 175 thread 1 is running ,thread 1 count = 180 thread 1 is running ,thread 1 count = 185 thread 1 is running ,thread 1 count = 190 thread 1 is running ,thread 1 count = 195 thread 1 is running ,thread 1 count = 200 thread 1 is running ,thread 1 count = 205 thread 2 is running ,thread 2 count = 0 thread 2 is running ,thread 2 count = 5 thread 2 is running ,thread 2 count = 10 thread 2 is running ,thread 2 count = 15 thread 2 is running ,thread 2 count = 20 thread 2 is running ,thread 2 count = 25 thread 2 is running ,thread 2 count = 30 thread 2 is running ,thread 2 count = 35 thread 2 is running ,thread 2 count = 40 thread 2 is running ,thread 2 count = 45 thread 2 is running ,thread 2 count = 50 thread 2 is running ,thread 2 count = 55 thread 2 is running ,thread 2 count = 60 thread 2 is running ,thread 2 count = 65 thread 2 is running ,thread 2 count = 70 thread 2 is running ,thread 2 count = 75 thread 2 is running ,thread 2 count = 80 thread 2 is running ,thread 2 count = 85 thread 2 is running ,thread 2 count = 90 thread 2 is running ,thread 2 count = 95 thread 2 is running ,thread 2 count = 100 thread 2 is running ,thread 2 count = 105 thread 2 is running ,thread 2 count = 110 thread 2 is running ,thread 2 count = 115 thread 2 is running ,thread 2 count = 120 thread 2 is running ,thread 2 count = 125 thread 2 is running ,thread 2 count = 130 thread 2 is running ,thread 2 count = 135 thread 2 is running ,thread 2 count = 140 thread 2 is running ,thread 2 count = 145 thread 2 is running ,thread 2 count = 150 thread 2 is running ,thread 2 count = 155 thread 2 is running ,thread 2 count = 160 thread 2 is running ,thread 2 count = 165 thread 2 is running ,thread 2 count = 170 thread 2 is running ,thread 2 count = 175 thread 2 is running ,thread 2 count = 180 thread 2 is running ,thread 2 count = 185 thread 2 is running ,thread 2 count = 190 thread 2 is running ,thread 2 count = 195 thread 2 is running ,thread 2 count = 200 thread 2 is running ,thread 2 count = 205 msh > ``` 使用RT—Thread-studio创建工程,跑timeslice_sample的示例程序运行结果如下: ``` msh >timeslice_sample msh >thread 1 is running ,thread 1 count = 0 thread 1 is running ,thread 1 count = 5 thread 1 is running ,thread 2 count = 135thread 1 is running ,thread 1 count = 15 thread 1 is running ,thread 2 count = 205thread 1 is running ,thread 1 count = 25 thread 1 is running ,thread 1 count = 30 thread 1 is running ,thread 1 count = 35 thread 1 is running ,thread 1 count = 40 thread 1 is running ,thread 1 count = 45 thread 1 is running ,thread 1 count = 50 thread 1 is running ,thread 1 count = 55 thread 1 is running ,thread 1 count = 60 thread 1 is running ,thread 1 count = 65 thread 1 is running ,thread 1 count = 70 thread 1 is running ,thread 1 count = 75 thread 1 is running ,thread 1 count = 80 thread 1 is running ,thread 1 count = 85 thread 1 is running ,thread 1 count = 90 thread 1 is running ,thread 1 count = 95 thread 1 is running ,thread 1 count = 100 thread 1 is running ,thread 1 count = 105 thread 1 is running ,thread 1 count = 110 thread 1 is running ,thread 1 count = 115 thread 1 is running ,thread 1 count = 120 thread 1 is running ,thread 1 count = 125 thread 1 is running ,thread 1 count = 130 thread 1 is running ,thread 1 count = 135 thread 1 is running ,thread 1 count = 140 thread 1 is running ,thread 1 count = 145 thread 1 is running ,thread 1 count = 150 thread 1 is running ,thread 1 count = 155 thread 1 is running ,thread 1 count = 160 thread 1 is running ,thread 1 count = 165 thread 1 is running ,thread 1 count = 170 thread 1 is running ,thread 1 count = 175 thread 1 is running ,thread 1 count = 180 thread 1 is running ,thread 1 count = 185 thread 1 is running ,thread 1 count = 190 thread 1 is running ,thread 1 count = 195 thread 1 is running ,thread 1 count = 200 thread 1 is running ,thread 1 count = 205 ``` 如上所示,结果不一样
查看更多
zhkag
2021-06-08
这家伙很懒,什么也没写!
你看tshell的优先级一样吗? tshell的优先级对它也是有影响的
2
个回答
默认排序
按发布时间排序
flashman2002
2021-06-08
这家伙很懒,什么也没写!
就是2个线程轮询,因为优先级一样,结果应该一致才对,编译器有所不同,优化的效果可能也不一样。
撰写答案
登录
注册新账号
关注者
0
被浏览
768
关于作者
CTUS_9871
这家伙很懒,什么也没写!
提问
1
回答
1
被采纳
0
关注TA
发私信
相关问题
1
关于时间片轮询中优先级高低导致轮询出错的问题
2
时间片轮转调度,,,,,,,,
3
时间片轮转调度,,,,,,
4
线程创建函数create最后的tick的作用?
5
RT-Thread 时间片示例问题
6
时间片例程 结果和pdf给出的结果不同
7
新手问题:刚开始学,看到优先级和时间片,有个问题问一下
8
没有相同优先级线程时,线程时间片的问题
9
关于互斥量与线程时间片的问题
10
时间片调度与超时调度
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RT-Thread项目助手v0.2.0 - 支持Env Windows
2
RttreadV5.10上,GD32F450Z RTC时间显示问题
3
rt-smart启动流程分析
4
EtherKit快速上手PROFINET
5
RTThread USB转串口无法接收数据
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
PWM
cubemx
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
出出啊
1517
个答案
342
次被采纳
小小李sunny
1444
个答案
290
次被采纳
张世争
813
个答案
177
次被采纳
crystal266
547
个答案
161
次被采纳
whj467467222
1222
个答案
149
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
3
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部