Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
邮箱_mailbox
超时
mailbox接收函数对于超时时间的处理疑问
发布于 2020-08-24 15:01:31 浏览:1178
订阅该版
在`rt_mb_recv`函数中为什么要通过一个while循环来判断是否有邮件到达,按说`rt_schedule`返回之后,如果是因为超时或者邮箱被删除或脱离,就会直接返回错误了;否则就是收到了邮件,`rt_schedule`才会返回。如果是这样,为什么最后还要判断timeout是否大于0呢?为什么不是与semaphore或者mutex等相同的处理方式? ```c /* src/ipc.c */ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) { ... /* mailbox is empty */ while (mb->entry == 0) { /* reset error number in thread */ thread->error = RT_EOK; /* no waiting, return timeout */ if (timeout == 0) { /* enable interrupt */ rt_hw_interrupt_enable(temp); thread->error = -RT_ETIMEOUT; return -RT_ETIMEOUT; } RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ rt_ipc_list_suspend(&(mb->parent.suspend_thread), thread, mb->parent.parent.flag); /* has waiting time, start thread timer */ if (timeout > 0) { /* get the start tick of timer */ tick_delta = rt_tick_get(); RT_DEBUG_LOG(RT_DEBUG_IPC, ("mb_recv: start timer of thread:%s\n", thread->name)); /* reset the timeout of thread timer and start it */ rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout); rt_timer_start(&(thread->thread_timer)); } /* enable interrupt */ rt_hw_interrupt_enable(temp); /* re-schedule */ rt_schedule(); /* resume from suspend state */ if (thread->error != RT_EOK) { /* return error */ return thread->error; } /* disable interrupt */ temp = rt_hw_interrupt_disable(); /* if it's not waiting forever and then re-calculate timeout tick */ if (timeout > 0) { tick_delta = rt_tick_get() - tick_delta; timeout -= tick_delta; if (timeout < 0) timeout = 0; } } ... } ```
查看更多
qq_还没想好
2020-08-24
这家伙很懒,什么也没写!
举一个极端情况的例子 A B 两个线程。A 线程优先级比 B 线程高。 B 线程等待接收邮箱,线程挂起 A 线程发送邮箱后,又从邮箱中取出。此时 B 线程被唤醒了,但是邮箱中又没有消息,超时时间也没有到。B 线程将再次挂起
2
个回答
默认排序
按发布时间排序
Jone
2020-08-24
写了还是懒
没研究过为什么要用while,最底下的对timeout是否大于零其实是判断timeout参数是否为`RT_WAITING_FOREVER`,此宏定义在rtt里定义为-1: ``` #define RT_WAITING_FOREVER -1 ```
撰写答案
登录
注册新账号
关注者
0
被浏览
1.2k
关于作者
Remember
这家伙很懒,什么也没写!
提问
8
回答
60
被采纳
16
关注TA
发私信
相关问题
1
邮箱阻塞接收设为永久阻塞却收到了RT_ETIMEOUT错误码
2
mailbox 邮件收发只能在一个文件中进行
3
关于事件集和邮箱那一块
4
邮箱能否支持多个收听?
5
关于邮箱传递消息,当消息很长的时候
6
一对多线程间通信的问题
7
邮箱,队列,信号在LCD菜单中内容刷新的选用
8
关于邮箱的疑问(如何解决在接收端处理速度慢情况下的同地址发送内容)
9
使用邮箱在某些情况下收不到邮件
10
线程1对多通信 使用邮箱吗
推荐文章
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动态模块
2
RT-Thread项目助手v0.3 | Ubuntu与MacOS平台的RT-Thread Env
3
【FRA156测评DM-MCX】- 环境配置篇
4
【基于HPM6750+RW007的网页服务器】---SD卡文件系统
5
有关RT_thread studio使用WDT的一点经验
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
rt-smart
RTC
FAL
I2C_IIC
ESP8266
UART
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
GD32
定时器
ADC
flashDB
编译报错
socket
中断
rt_mq_消息队列_msg_queue
Debug
keil_MDK
SFUD
msh
ulog
C++_cpp
MicroPython
本月问答贡献
lchnu
3
个答案
2
次被采纳
张世争
1
个答案
2
次被采纳
a1012112796
9
个答案
1
次被采纳
三世执戟
8
个答案
1
次被采纳
聚散无由
5
个答案
1
次被采纳
本月文章贡献
jinchanchan
9
篇文章
13
次点赞
ssdd45555
3
篇文章
2
次点赞
聚散无由
1
篇文章
4
次点赞
rvcore
1
篇文章
1
次点赞
lvdongchina
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部