一个很奇怪的问题,Xtang大侠帮忙回答下。

1 我以前用PHAB画了个界面,但是那台电脑不是很好用,所以我把整个PHAB工程文件夹都拷贝到了另一台装了QNX的电脑上(由于不知道原因到底是什么,所以啰嗦的把过程讲清楚些)
2 我在那台电脑上用PHAB 打开了整个工程。然后我想在abmain.c中将我想要的所有其他线程启动起来,所以我改了abmain.c

#include “Thread.h”





int
main ( int argc, char *argv[] )
{
Ap.Ap_winstate = 0;

/* AppBuilder Initialization */
ApInitialize( argc, argv, &AbContext );

PgSetDrawBufferSize( 0xffff );
//sleep(2);
/* Display main window /
ApLinkWindow( NULL, &AbApplLinks[0], NULL );
StartAllThread();//这个是我加上去的,它在Thread.h文件中
/
Loop until user quits application /
PtMainLoop( );
PtExit( 0 );
return 0;
}
上面的StartAllThread()是我加到abmain.c中的,它是在Thread.h中。
Thread.h:
void
ReceiveThread(void* arg);
void* SendThread(void* arg);
void StartAllThread(void);
void StartAllThread()
{
pthread_attr_t attr1;
pthread_attr_t attr2;
pthread_attr_init(&attr1);
pthread_create(NULL,&attr1,&ReceiveThread, NULL);
pthread_attr_init(&attr2);
pthread_create(NULL,&attr2,&SendThread, NULL);
}
void *SendThread(void *arg)
{
int code;
int value;
int priority=getprio(0);
printf("%d\n",chid);
// sleep(5);
coid=ConnectAttach(ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0);
code=MY_PULSE_FLAP1;
value=20;
MsgSendPulse(coid,priority,code,value);
//sleep(10);
code=MY_PULSE_FLAP2;
value=80;
MsgSendPulse(coid,priority,code,value);
code=MY_PULSE_POWERSWITCH;
value=1;
MsgSendPulse(coid,priority,code,value);

code=MY_PULSE_EMGSWITCH;
value=1;
MsgSendPulse(coid,priority,code,value);
code=MY_PULSE_LOCAL_429;
value=0x000800E2;
MsgSendPulse(coid,priority,code,value);
code=MY_PULSE_HANDLE;
value=4;
MsgSendPulse(coid,priority,code,value);
}
void* ReceiveThread(void* arg)
{
struct _pulse pulse;
chid = ChannelCreate(0);
for(;:wink:
{
rcvid = MsgReceivePulse(chid, &pulse,sizeof( pulse ), NULL );
switch(pulse.code)
{
case MY_PULSE_FLAP1:{Handle_Flap1pulse(pulse);break;}
case MY_PULSE_FLAP2:{Handle_Flap2pulse(pulse);break;}
case MY_PULSE_HANDLE:{Handle_Handlepulse(pulse);break;}
case MY_PULSE_POWERSWITCH:{Handle_Powerswitchpulse(pulse);break;}
case MY_PULSE_EMGSWITCH:{Handle_Emgswitchpulse(pulse);break;}
case MY_PULSE_FSOS1:{Handle_Fsos1pulse(pulse);break;}
case MY_PULSE_FSOS2:{Handle_Fsos2pulse(pulse);break;}
case MY_PULSE_LOCAL_429:{Handle_429pulse(pulse);break;}
case MY_PULSE_NETWORK_429:{Handle_429pulse(pulse);break;}
default:{}
}
}

}
我在StartAllThread()中启动了两个线程SendThread和ReceiveThread,问题就是1 SendThread中的那句printf("%d\n",chid)不能被删除或注释,已删除或注释,我的整个工程就启动不起来了。
2 为什么在SendThread中sleep(5)不能用呢?那句话不注释的话,程序执行到sleep(5),等5秒记完时程序也自动退除了,不知道是怎么回事。
3 在Thread.h中Timer也不能用了,和SLEEP差不多第一次记完时后程序就推出了
谢谢回答啊!