PtSetResource() 导致 Memory fault 的原因分析
2015-12-27 15:17
330 查看
最近在开发 QNX 界面程序的过程中出现一个奇怪的BUG:从串口程序获取到数据后,写入到 控件值的时候会发生内存错误
如下:
PtSetResource( pWidget , Pt_ARG_TEXT_STRING, TmpStr , 0 ) ;
Memory fault
试验一:
在main() 函数中设置固定值,设置成功;
PtSetResource(ABW_PtText_AxleTemp_OutTemp,Pt_ARG_TEXT_STRING , "123" , 0 ) ;
实验二:
在串口接收线程内设置固定值, 设置失败;
PtSetResource(ABW_PtText_AxleTemp_OutTemp,Pt_ARG_TEXT_STRING , "123" , 0 ) ;
然后调出样例程序,参考其设置方法,在设置前后
PtEnter( Pt_EVENT_PROCESS_PREVENT) + PtLeave(eval ),
成功!
if ((eval = MyPtEnter()) >= 0)
{
ResolveCurData(msg_ptr, CmdLength);
MyPtLeave( eval ) ;
}
分析:
PtEnter()
Lockthe Photon library for use by a single thread /// 锁定ph库,在当前线程中使用
Synopsis:
intPtEnter( int flags );
Arguments:
The value of flags can be 0 or oneof:
Pt_EVENT_PROCESS_ALLOW
Consider the calling thread an eventreader.
Pt_EVENT_PROCESS_PREVENT
Consider the calling thread a nonreader.
In most cases, it's better to set neitherof these bits in flags, in which case the thread's status as eventreader or nonreader doesn't change. For more information about changing athread's event reader status, see “Threads”in
the Parallel Operations chapter of the Photon Programmer's Guide.
You can OR the following into the flags:
Pt_DELAY_EXIT
Prevent another thread from terminating theprocess by calling
PtExit().
Library:
ph
总结:
在 QNX的界面程序开发中涉及到控件设置的操作,注意是否是多线程,如果是多线程,需要按照先锁定库, 再设置, 最后再释放库 的顺序进行设置。
如下:
PtSetResource( pWidget , Pt_ARG_TEXT_STRING, TmpStr , 0 ) ;
Memory fault
试验一:
在main() 函数中设置固定值,设置成功;
PtSetResource(ABW_PtText_AxleTemp_OutTemp,Pt_ARG_TEXT_STRING , "123" , 0 ) ;
实验二:
在串口接收线程内设置固定值, 设置失败;
PtSetResource(ABW_PtText_AxleTemp_OutTemp,Pt_ARG_TEXT_STRING , "123" , 0 ) ;
然后调出样例程序,参考其设置方法,在设置前后
PtEnter( Pt_EVENT_PROCESS_PREVENT) + PtLeave(eval ),
成功!
if ((eval = MyPtEnter()) >= 0)
{
ResolveCurData(msg_ptr, CmdLength);
MyPtLeave( eval ) ;
}
分析:
PtEnter()
Lockthe Photon library for use by a single thread /// 锁定ph库,在当前线程中使用
Synopsis:
intPtEnter( int flags );
Arguments:
The value of flags can be 0 or oneof:
Pt_EVENT_PROCESS_ALLOW
Consider the calling thread an eventreader.
Pt_EVENT_PROCESS_PREVENT
Consider the calling thread a nonreader.
In most cases, it's better to set neitherof these bits in flags, in which case the thread's status as eventreader or nonreader doesn't change. For more information about changing athread's event reader status, see “Threads”in
the Parallel Operations chapter of the Photon Programmer's Guide.
You can OR the following into the flags:
Pt_DELAY_EXIT
Prevent another thread from terminating theprocess by calling
PtExit().
Library:
ph
总结:
在 QNX的界面程序开发中涉及到控件设置的操作,注意是否是多线程,如果是多线程,需要按照先锁定库, 再设置, 最后再释放库 的顺序进行设置。
相关文章推荐
- 基于C/S模式的简单聊天程序(服务器篇)
- 150,项目管理器git的使用
- 扣丁学堂——文件管理
- 系统设计与实践(实战演练)
- 利用泛型抽取Dao层,加事务注解问题(java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType)
- MUI如何有效的在浏览器中进行调试
- printf()函数常用格式控制
- model传值
- android之旅11 网络编程实例:多线程下载与断点续传
- Android混淆、反编译基础教程
- 设计模式六大原则(6):开闭原则
- 堆栈,堆栈,堆和栈的区别
- 【虚幻4】学习总结2-蓝图入门1
- Directory.GetFiles 方法
- Spring MVC的路径匹配
- meteor框架学习
- Linux系统下Oracle数据库的安装和启动关闭操作教程
- 对象存储Object,分布式文件存储NAS,分布式块存储(ServerSAN)
- 51NOD 1031 骨牌覆盖
- myeclipse 开发最常用实用快捷键