Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread一般讨论
下面的程序运行结果怎么会是这样
发布于 2009-09-08 13:14:23 浏览:8881
订阅该版
void thread1_entry(void *param) { while(1) { rt_kprintf(" Thread1 :delay 1s
"); rt_thread_delay(100); rt_mutex_take(&mutex,RT_WAITING_FOREVER); rt_kprintf(" Thread1 : taken mutex
"); rt_thread_delay(500); rt_mutex_release(&mutex); rt_kprintf("thread1:release mutex
"); } } void thread2_entry(void *param) { while(1) { rt_mutex_take(&mutex,RT_WAITING_FOREVER); rt_kprintf(" Thread2 : taken mutex
"); rt_thread_delay(500); rt_mutex_release(&mutex); rt_kprintf("thread2:release mutex
"); } } int application_thread_Create(void) { rt_thread_t init_thread; rt_mutex_init(&mutex,"mutext",RT_IPC_FLAG_FIFO); init_thread = rt_thread_create("t1",thread1_entry, RT_NULL,512,250,10); if(init_thread==RT_NULL) rt_kprintf("thread1_entry is created fail"); rt_thread_startup(init_thread); init_thread = rt_thread_create("t2",thread2_entry, RT_NULL,512,200,10); if(init_thread==RT_NULL) rt_kprintf("thread2_entry is created fail"); rt_thread_startup(init_thread); return 0; }
查看更多
14
个回答
默认排序
按发布时间排序
mgdsun2000
2009-09-08
这家伙很懒,什么也没写!
下面是程序的运行结果。我的问题是: 1)为什么打 [s:188] 两行会Thread2和Thread1 都得到taken mutex? 2) 为什么最后高优先级的Thread2得不到taken mutex?如果提高优先级thread1,也应当轮换啊 Thread2 : taken mutex Thread1 :delay 1s thread2:release mutex Thread2 : taken mutex [s:188] Thread1 : taken mutex [s:188] thread2:release mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex Thread1 :delay 1s Thread1 : taken mutex thread1:release mutex
bernard
2009-09-08
这家伙很懒,什么也没写!
[s:188] 在哪里?指的结果上的 而 非代码上的?
mgdsun2000
2009-09-09
这家伙很懒,什么也没写!
>:?: > >在哪里?指的结果上的 而 非代码上的? --- 指的是运行结果上的问号。
bernard
2009-09-09
这家伙很懒,什么也没写!
似乎有问题,t1似乎是被错误的唤醒了
mgdsun2000
2009-09-09
这家伙很懒,什么也没写!
>似乎有问题,t1似乎是被错误的唤醒了 --- 是程序问题么? 看不出来有什么问题啊。
bernard
2009-09-09
这家伙很懒,什么也没写!
>>似乎有问题,t1似乎是被错误的唤醒了 > >--- > >是程序问题么? >看不出来有什么问题啊。 --- OS的问题,目前确认了,会尽快修正。谢谢!
bernard
2009-09-10
这家伙很懒,什么也没写!
这个问题已经修正,并且针对于mailbox及message queue将采取更为严格的措施,请更新到svn最新版本。 mutex相应的测试代码: ``` /* * File : tc001_thread.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://openlab.rt-thread.com/license/LICENSE * * Change Logs: * Date Author Notes * 2006-05-29 Bernard the first version */ #include
struct rt_thread thread1; struct rt_thread thread2; char thread1_stack[512]; char thread2_stack[512]; struct rt_mutex mutex; void thread1_entry(void *param) { while(1) { rt_mutex_take(&mutex, RT_WAITING_FOREVER); rt_mutex_take(&mutex, RT_WAITING_FOREVER); rt_kprintf("thread1: taken mutex "); rt_thread_delay(50); rt_kprintf("thread1: release mutex "); rt_mutex_release(&mutex); rt_mutex_release(&mutex); } } void thread2_entry(void *param) { while(1) { rt_kprintf("thread2: delay 1second "); rt_thread_delay(10); rt_mutex_take(&mutex, RT_WAITING_FOREVER); rt_kprintf("thread2: taken mutex "); rt_thread_delay(100); rt_mutex_release(&mutex); } } int rt_application_init() { rt_mutex_init(&mutex, "mutext", RT_IPC_FLAG_FIFO); rt_thread_init(&thread1, "thread1", thread1_entry, RT_NULL, &thread1_stack[0], sizeof(thread1_stack), 25, 10); rt_thread_init(&thread2, "thread2", thread2_entry, RT_NULL, &thread2_stack[0], sizeof(thread2_stack), 20, 7); rt_thread_startup(&thread1); rt_thread_startup(&thread2); return 0; } ```
mgdsun2000
2009-09-10
这家伙很懒,什么也没写!
下面是更新库程序后的运行结果。好像还是有问题啊?线程1和线程2还是同时得到了taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex [s:188] mutex_thread2_entry: taken mutex [s:188] mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex
bernard
2009-09-10
这家伙很懒,什么也没写!
这次应该好了,mutex的value忘记修正了。
mgdsun2000
2009-09-10
这家伙很懒,什么也没写!
好像还是不对?库更新了么? mutex_thread2_entry: taken mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex mutex_thread2_entry: taken mutex mutex_thread1_entry:release mutex mutex_thread1_entry :delay 1s mutex_thread2_entry:release mutex mutex_thread1_entry : taken mutex
撰写答案
登录
注册新账号
关注者
0
被浏览
8.9k
关于作者
mgdsun2000
这家伙很懒,什么也没写!
提问
7
回答
13
被采纳
0
关注TA
发私信
相关问题
1
有关动态模块加载的一篇论文
2
最近的调程序总结
3
晕掉了,这么久都不见layer2的踪影啊
4
继续K9ii的历程
5
[GUI相关] FreeType 2
6
[GUI相关]嵌入式系统中文输入法的设计
7
20081101 RT-Thread开发者聚会总结
8
嵌入式系统基础
9
linux2.4.19在at91rm9200 上的寄存器设置
10
[转]基于嵌入式Linux的通用触摸屏校准程序
推荐文章
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
如何在master上的BSP中添加配置yml文件
2
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
3
RT-Thread 发布 EtherKit开源以太网硬件!
4
rt-thread使用cherryusb实现虚拟串口
5
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
热门标签
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
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
ulog
C++_cpp
at_device
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
14
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
5
次点赞
RTT_逍遥
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部