您的位置:首页 > 其它

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的界面程序开发中涉及到控件设置的操作,注意是否是多线程,如果是多线程,需要按照先锁定库, 再设置, 最后再释放库 的顺序进行设置。

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: