完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在官方的消息队列例程中,用来发送消息的线程2每次循环延时5ms,接收消息的线程1延时50ms,为什么输出语句中显示线程2发送5次后线程1就结束挂起状态实现一次接收呢? #include <rtthread.h> \ | / RT - Thread Operating System |
|
相关推荐
4个回答
|
|
我实际测试了下,F407的板子
发送和接收中加入了rt_tick_get的打印 线程2里面的rt_thread_mdelay(5) 时间是不准确的 实际结果如下: | / - RT - Thread Operating System / | 4.0.2 build Sep 1 2021 2006 - 2019 Copyright by rt-thread team msh > msh > msh >ms msgq_sample msh >msgq_sample msh >thread2: send message - A 4557 thread1: recv msg from msg queue, the contthread2: send messageent:A 4561 - B 4565 thread2: send message - C 4574 thread2: send message - D 4582 thread2: send message - E 4590 thread2: send message - F 4598 thread2: send message - G 4606 thread2: send message - H 4614 thread1: recv msg from msg queue, the contthread2: seent:B 4618 nd urgent message - I 4622 thread2: send message - J 4631 thread2: send message - K 4639 thread2: send message - L 4647 thread2: send message - M 4655 thread2: send message - N 4663 thread2: send message - O 4671 thread1: recv msg from msg queue, the content:I 4674 thread2: send message - P 4683 thread2: send message - Q 4691 thread2: send message - R 4699 thread2: send message - S 4707 thread2: send message - T 4715 message queue stop send, thread2 quit thread1: recv msg from msg queue, the content:C 4729 thread1: recv msg from msg queue, the content:D 4784 thread1: recv msg from msg queue, the content:E 4839 thread1: recv msg from msg queue, the content:F 4894 thread1: recv msg from msg queue, the content:G 4949 thread1: recv msg from msg queue, the content:H 5004 thread1: recv msg from msg queue, the content:J 5059 thread1: recv msg from msg queue, the content:K 5114 thread1: recv msg from msg queue, the content:L 5169 thread1: recv msg from msg queue, the content:M 5224 thread1: recv msg from msg queue, the content:N 5279 thread1: recv msg from msg queue, the content:O 5334 thread1: recv msg from msg queue, the content:P 5389 thread1: recv msg from msg queue, the content:Q 5444 thread1: recv msg from msg queue, the content:R 5499 thread1: recv msg from msg queue, the content:S 5554 thread1: recv msg from msg queue, the content:T 5609 thread1: detach mq msh >ps thread pri status sp stack size max used left tick error -------- --- ------- ---------- ---------- ------ ---------- --- tshell 20 running 0x000000d0 0x00001000 15% 0x00000006 000 tidle0 31 ready 0x0000005c 0x00000100 51% 0x00000015 000 timer 4 suspend 0x0000007c 0x00000200 24% 0x00000009 000 main 10 suspend 0x000000bc 0x00000800 14% 0x00000014 000 |
|
|
|
谢谢回复!那理论上的结果应该是上图那样吗?(我的理解是线程1挂起时线程2可以发送10个消息,所以线程1第二个接收到的就是I,不知道哪里理解出了问题
|
|
|
|
|
|
|
|
把线程2的
延时 rt_thread_mdelay(5)修改为 rt_thread_mdelay(2) 实际如下 | / - RT - Thread Operating System / | 4.0.2 build Sep 1 2021 2006 - 2019 Copyright by rt-thread team msh >ms msgq_sample msh >msgq_sample msh >thread2: send message - A 4006 thread1: recv msg from msg queue, the content:Athread2: send message 4009 - B 4014 thread2: send message - C 4019 thread2: send message - D 4024 thread2: send message - E 4029 thread2: send message - F 4034 thread2: send message - G 4039 thread2: send message - H 4044 thread2: send urgent message - I 4049 thread2: send message - J 4054 thread2: send message - K 4059 m msg queuend messagethread1: recv msg from msg queue, the content:I 4066 thread2: send message - M 4074 thread2: send message - N 4079 thread2: send message - O 4084 thread2: send message - P 4089 thread2: send message - Q 4094 thread2: send message - R 4099 thread2: send message - S 4104 thread2: send message - T 4109 message queue stop send, thread2 quit thread1: recv msg from msg queue, the content:B 4122 thread1: recv msg from msg queue, the content:C 4177 thread1: recv msg from msg queue, the content:D 4232 thread1: recv msg from msg queue, the content:E 4287 thread1: recv msg from msg queue, the content:F 4342 thread1: recv msg from msg queue, the content:G 4397 thread1: recv msg from msg queue, the content:H 4452 thread1: recv msg from msg queue, the content:J 4507 thread1: recv msg from msg queue, the content:K 4562 thread1: recv msg from msg queue, the content:L 4617 thread1: recv msg from msg queue, the content:M 4672 thread1: recv msg from msg queue, the content:N 4727 thread1: recv msg from msg queue, the content:O 4782 thread1: recv msg from msg queue, the content:P 4837 thread1: recv msg from msg queue, the content:Q 4892 thread1: recv msg from msg queue, the content:R 4947 thread1: recv msg from msg queue, the content:S 5002 thread1: recv msg from msg queue, the content:T 5057 thread1: detach mq |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
792 浏览 0 评论
4507 浏览 0 评论
如何使用python调起UDE STK5.2进行下载自动化下载呢?
2564 浏览 0 评论
开启全新AI时代 智能嵌入式系统快速发展——“第六届国产嵌入式操作系统技术与产业发展论坛”圆满结束
2939 浏览 0 评论
获奖公布!2024 RT-Thread全球巡回线下培训火热来袭!报名提问有奖!
31587 浏览 11 评论
72967 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 19:42 , Processed in 0.685786 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号