Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
事件集
FIFO
事件集先进先出方式如何理解?
发布于 2021-08-18 21:42:00 浏览:689
订阅该版
修改了下参考文档中的事件集例程,采用RT_IPC_FLAG_FIFO方式,线程1和3等待相同事件集(事件接受设置为不清除),事件集唤醒线程后则打印线程退出;线程2发送事件集。结果显示线程1、3唤醒的顺序与线程挂起的顺序无关,与线程1、3优先级有关,高优先级先执行,低优先级后执行。 注: 1)RTT:V4.0.3, IDE:VSCode , BSP:qemu-express-a9 线程1初始化后延时100ms等待事件集;线程3初始化后直接等待事件集;即等待顺序为线程3在前,线程1在后,Finsh执行list_event看到的等待线程顺序与此一致; 2)测试代码优先级线程1高于线程3,等待顺序为线程3、线程1,线程接收事件集顺序为线程1、线程3,即与先进先出不符,与优先级相符; 3)交换线程1、线程3优先级,则线程接收事件集顺序为线程3、线程1,还是与优先级相符。 请问是不是对FIFO方式理解有误,线程等待顺序与等待线程列表里的顺序不是一回事?理解是否可推广道其它同步方式? 测试代码: ```c #include
#include "thread_exp.h" #define THREAD_PRIORITY 9 #define THREAD_TIMESLICE 5 #define EVENT_FLAG1 (1 << 0) #define EVENT_FLAG2 (1 << 1) #define EVENT_FLAG3 (1 << 2) #define EVENT_FLAG4 (1 << 3) #define EVENT_FLAG5 (1 << 4) #define EVENT_FLAG6 (1 << 5) /* 事件控制块 */ static struct rt_event event; ALIGN(RT_ALIGN_SIZE) static char thread1_stack[1024]; static struct rt_thread thread1; /* 线程 1 入口函数 */ static void thread1_recv_event(void *param) { rt_uint32_t e; /* rt_kprintf("thread1 waitting for 1 and 2.\n"); if (rt_event_recv(&event, (EVENT_FLAG1 | EVENT_FLAG2), RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { rt_kprintf("thread1: OR recv event 0x%x\n", e); } */ //rt_kprintf("thread1: delay 1s to prepare the second event\n"); rt_thread_mdelay(100); rt_kprintf("thread1 waitting for 4 and 5.\n"); if (rt_event_recv(&event, (EVENT_FLAG4 | EVENT_FLAG5), RT_EVENT_FLAG_AND, RT_WAITING_FOREVER, &e) == RT_EOK) { rt_kprintf("thread1: AND recv event 0x%x\n", e); } rt_kprintf("thread1 leave.\n"); } ALIGN(RT_ALIGN_SIZE) static char thread3_stack[1024]; static struct rt_thread thread3; /* 线程 1 入口函数 */ static void thread3_recv_event(void *param) { rt_uint32_t e; rt_kprintf("thread3 waitting for 4 and 5.\n"); /* 第二次接收事件,事件 3 和事件 5 均发生时才可以触发线程 1,接收完后清除事件标志 */ if (rt_event_recv(&event, (EVENT_FLAG4 | EVENT_FLAG5), RT_EVENT_FLAG_AND, RT_WAITING_FOREVER, &e) == RT_EOK) { rt_kprintf("thread3: AND recv event 0x%x\n", e); } rt_kprintf("thread3 leave.\n"); } ALIGN(RT_ALIGN_SIZE) static char thread2_stack[1024]; static struct rt_thread thread2; /* 线程 2 入口 */ static void thread2_send_event(void *param) { rt_thread_mdelay(2000); rt_kprintf("thread2: send event1\n"); rt_event_send(&event, EVENT_FLAG1); rt_thread_mdelay(200); rt_kprintf("thread2: send event2\n"); rt_event_send(&event, EVENT_FLAG2); rt_thread_mdelay(200); rt_kprintf("thread2: send event3\n"); rt_event_send(&event, EVENT_FLAG3); rt_thread_mdelay(200); rt_kprintf("thread2: send event4\n"); rt_event_send(&event, EVENT_FLAG4); rt_thread_mdelay(200); rt_kprintf("thread2: send event5\n"); rt_event_send(&event, EVENT_FLAG5); rt_kprintf("thread2 leave.\n"); } int event_sample(void) { rt_err_t result; //rt_scheduler_sethook(hook_of_scheduler); /* 初始化事件对象 */ result = rt_event_init(&event, "event", RT_IPC_FLAG_FIFO); if (result != RT_EOK) { rt_kprintf("init event failed.\n"); return -1; } rt_thread_init(&thread1, "thread1", thread1_recv_event, RT_NULL, &thread1_stack[0], sizeof(thread1_stack), THREAD_PRIORITY - 2, THREAD_TIMESLICE); rt_thread_startup(&thread1); rt_thread_init(&thread3, "thread3", thread3_recv_event, RT_NULL, &thread3_stack[0], sizeof(thread3_stack), THREAD_PRIORITY-1, THREAD_TIMESLICE); rt_thread_startup(&thread3); rt_thread_init(&thread2, "thread2", thread2_send_event, RT_NULL, &thread2_stack[0], sizeof(thread2_stack), THREAD_PRIORITY, THREAD_TIMESLICE); rt_thread_startup(&thread2); return 0; } ``` 结果如下: ``` \ | / - RT - Thread Operating System / | \ 4.0.3 build Aug 16 2021 2006 - 2021 Copyright by rt-thread team lwIP-2.0.2 initialized! [32m[I/sal.skt] Socket Abstraction Layer initialize success.[0m [32m[I/SDIO] SD card capacity 65536 KB.[0m [32m[I/SDIO] switching card to high speed failed![0m hello rt-thread msh />ev event_sample msh />event_sample thread3 waitting for 4 and 5. msh />thread1 waitting for 4 and 5. thread2: send event1 thread2: send event2 thread2: send event3 thread2: send event4 thread2: send event5 thread1: AND recv event 0x18 thread1 leave. thread3: AND recv event 0x18 thread3 leave. thread2 leave. ```
查看更多
1
个回答
默认排序
按发布时间排序
出出啊
2021-08-19
致男人们:劝说是不会有成果的。 —— 《单向街》
RT_IPC_FLAG_FIFO 的意思是,谁先申请事件集,事件集条件满足的时候先紧着谁唤醒。 但是官方目前不建议使用这中方式,换优先级方式 RT_IPC_FLAG_FIFO 吧。
撰写答案
登录
注册新账号
关注者
0
被浏览
689
关于作者
coolouba
这家伙很懒,什么也没写!
提问
3
回答
9
被采纳
0
关注TA
发私信
相关问题
1
有单独清除事件标志的函数么?
2
事件集的选择清除重置事件标志位
3
关于事件集和邮箱那一块
4
rt-thread事件集多线程接收的一个疑问?
5
事件集在中断服务函数与线程之间的同步的疑问
6
生产者消费者中是否可以使用一个事件集来代替多个二值信号量?
7
一对多线程间通信的问题
8
事件使用RT_EVENT_FLAG_CLEAR标志位无法清0
9
rt_thread事件集使用问题
10
rt_thread事件集
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
五分钟玩转RT-Thread新社区
5
国产MCU移植系列教程汇总,欢迎查看!
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 with VS Code之MacOS篇
2
RT-Thread开发GD32F450 添加串口外设,以及一种串口接收数据处理的方法
3
RT-Thread Studio软件正常下载,终端串口不显示问题
4
STM32H750 在RT-Thread Studio上配置CANFD驱动普通CAN模式控制大疆M3508电机
5
RT-Thread with VS Code之Windows篇
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
FinSH
Bootloader
CAN总线
ART-Pi
Hardfault
文件系统
USB
DMA
RT-Thread
线程
SCons
RT-Thread Nano
stm32
MQTT
ESP8266
ota
UART
RTC
rtthread
rt-smart
packages_软件包
freemodbus
I2C
WIZnet_W5500
flash
cubemx
FAL
定时器
BSP
AB32VG1
PWM
ADC
SDIO
msh
socket
LVGL
keil
Debug
C++_cpp
中断
编译报错
SFUD
SMP
MicroPython
本月问答贡献
宇宙码蚁
45
个答案
6
次被采纳
xiaorui
27
个答案
4
次被采纳
lchnu
15
个答案
4
次被采纳
Ryan_CW
6
个答案
4
次被采纳
张世争
5
个答案
3
次被采纳
本月文章贡献
张世争
6
篇文章
14
次点赞
YZRD
6
篇文章
9
次点赞
快乐小鸟
4
篇文章
4
次点赞
RTT_逍遥
3
篇文章
24
次点赞
recan
3
篇文章
19
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部