|
代码如下:
pthread_cond_t WaitEvent; //等待事件阻塞
pthread_mutex_t Inuse; //临时使用
if(readKey(&Key)==0){
return(Key);
}
else{
ts.tv_sec = time(NULL) + 5;
printf("MainKeyboard:: get wait time\n");
//pthread_mutex_lock(&Inuse);
pthread_cond_timedwait(&WaitEvent,&Inuse,&ts);
printf("MainKeyboard::get out time\n");
if(readKey(&Key)==0){
printf("Onkey read Key OK :%d\n",Key);
//sem_post(&Sem_KeyboardEnable);
return(Key) ;
}
else{
printf("Onkey read Key Faulse \n");
//sem_post(&Sem_KeyboardEnable);
return(0);
}
}
另外一个线程:
int MainKeyboard::run(){
char Key;
while(1){
Key=OnKeyevent();//MainInterface.process();
writeKey(Key);
pthread_cond_signal(&WaitEvent);
printf("MainKeyboard::run send WaitEvert\n");
}
}
其中OnKeyevent()读取一个阻塞型串口。
运行重出现的问题:没有在 pthread_cond_timedwait(&WaitEvent,&Inuse,&ts);地方挂起延时。一直向下执行。
请教什么问题? |
|