LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1525|回复: 16

昏晕几天!!!while(1)线程被莫名杀死!或阻塞!呜呜。。。

[复制链接]
发表于 2006-11-10 11:45:21 | 显示全部楼层 |阅读模式
昏晕几天!!!while(1)线程被莫名杀死!或阻塞!求救。。。
( 俺不知道while(1)函数的实例是否叫线程,若有错,请指正)

main()
{
   ......
   ......
   while(1){
// 如果没有输入就继续循环
// 若有输入就执行以下程序
  ......
   ......
  }
}

/* 中断处理函数,没各1秒钟,内核唤醒执行,可以中断while(1)循环 */
void inthandler()
{ printf("......");
   // 画一个圆圈
  .......
}

请问!!!中断处理函数有可能杀死while(1)或阻塞它么???
若有,那是什么样的情况?

呜呜。。。我想晕了。。。不得其解!

现实情况:
    程序执行后,while(1)转了几圈之后就停止了,只有中断程序还按时中断执行。。。。
 楼主| 发表于 2006-11-10 11:54:16 | 显示全部楼层

补充

我是在没有按下按键的情况下被杀死/阻塞的,也就是说

在while(1)那里,没有输入,它一直循环查找输入,没有执行往下的语句,

却不过1、2秒就停止循环查找输入了
回复 支持 反对

使用道具 举报

发表于 2006-11-10 13:03:11 | 显示全部楼层
你的main到底是被阻塞了,还是退出结束了?
回复 支持 反对

使用道具 举报

发表于 2006-11-10 13:07:01 | 显示全部楼层
还有你所谓的“中断处理函数”是指singal handler吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-10 14:19:17 | 显示全部楼层
是的,没错。请指教
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-10 17:01:59 | 显示全部楼层
main 应该还没有结束,因为中断还有响应,就是动不了了
回复 支持 反对

使用道具 举报

发表于 2006-11-10 17:45:38 | 显示全部楼层
个人感觉有两种可能:
1. 你的while(1)循环有问题,导致到后来的读/写block;
2. 你的signal handler有问题,在signal handler中block,当然无法返回while循环中的中断点继续执行;然而,如果你的signal handle没有mask同种signal的话,随着这种signal的继续发生,signal handler还会不断继续得到调用,当然,每次signal handler执行到中间都会block,所以interrupt stack会越来越深,到最后肯定会耗尽内存;

看样子,2的可能性大一点。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-10 21:03:36 | 显示全部楼层
你等等,我一会儿回来,嘻嘻,先谢了,忙中。。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-10 22:03:31 | 显示全部楼层
请仁兄看看测试结果:
【this is the start of the while(1) loop: loop xxxx】表示while(1)的第几个循环
没有 this is the end of  the while(1) ,因为它搜索不到输入就重新再循环

以下两句是放在中断处理的头一句和尾一句
【this is the start of the interrupt-handler  loop: loop xxxx】
【this is the end of the interrupt-handler  loop: loop xxxx】



input = -1
this is the start of the while(1) loop:  loop 12517
input = -1
this is the start of the while(1) loop:  loop 12518
input = -1
this is the start of the while(1) loop:  loop 12519
input = -1
this is the start of the while(1) loop:  loop 12520
input = -1
this is the start of the while(1) loop:  loop 12521
input = -1
this is the start of the while(1) loop:  loop 12522
input = -1
this is the start of the while(1) loop:  loop 12523
input = -1
this is the start of the while(1) loop:  loop 12524
input = -1
this is the start of the while(1) loop:  loop ttiittittittittittittitiitiitiiti1this is the start of the while(1) loop:  loop 12803
input = -1
this is the start of the while(1) loop:  loop 12804
input = -1
this is the start of the while(1) loop:  loop 12805
input = -1
this is the start of the while(1) loop:  loop 12806
input = -1
this is the start of the while(1) loop:  loop 12807
input = -1
this is the start of the while(1) loop:  loop 12808
input = -1
this is the start of the while(1) loop:  loop 12809
input = -1
this is the start of the while(1) loop:  loop 12810
input = -1
this is the start of the while(1) loop:  loop 12811
input = -1
this is the start of the while(1) loop:  loop 12812
input = -1
this is the start of the while(1) loop:  loop 12813
input = -1
this is the start of the while(1) loop:  loop 12814
input = -1
this is the start of the while(1) loop:  loopttiittittittiittittittitiitiitiiti2this is the start of the while(1) loop:  loop 13180
input = -1
this is the start of the while(1) loop:  loop 13181
input = -1
this is the start of the while(1) loop:  loop 13182
input = -1
this is the start of the while(1) loop:  loop 13183
input = -1
this is the start of the while(1) loop:  loop 13184
input = -1
this is the start of the while(1) loop:  loop 13185
input = -1
this is the start of the while(1) loop:  loop 13186
input = -1
this is the start of the while(1) loop:  loop 13187
input = -1
this is the start of the while(1) loop:  loop 13188
input = -1
this is the start of the while(1) loop:  loop 13189
input = -1
this is the start of the while(1) loop:  loop 13190
input = -1
this is the start of the while(1) loop:  loop 13191
input = -1
this is the start of the while(1) loop:  looptttittittittittiitiittittittittitt3this is the start of the while(1) loop:  loop 13558
input = -1
this is the start of the while(1) loop:  loop 13559
input = -1
this is the start of the while(1) loop:  loop 13560
input = -1
this is the start of the while(1) loop:  loop 13561
input = -1
this is the start of the while(1) loop:  loop 13562
input = -1
this is the start of the while(1) loop:  loop 13563
input = -1
this is the start of the while(1) loop:  loop 13564
input = -1
this is the start of the while(1) loop:  loop 13565
input = -1
this is the start of the while(1) loop:  loop 13566
input = -1
this is the start of the while(1) loop:  loop 13567
input = -1
this is the start of the while(1) loop:  loop 13568
input = -1
this is the start of the while(1) loop:  loop 13569
input = -1
this is the start of the while(1) loop:  loopiittiitiitiittittitiittittittittit4this is the start of the interrupt_handler: loop 35
this is the end of the interrupt_handler: loop 35
this is the start of the interrupt_handler: loop 36
this is the end of the interrupt_handler: loop 36
this is the start of the interrupt_handler: loop 37
this is the end of the interrupt_handler: loop 37
this is the start of the interrupt_handler: loop 38
this is the end of the interrupt_handler: loop 38
this is the start of the interrupt_handler: loop 39
this is the end of the interrupt_handler: loop 39
this is the start of the interrupt_handler: loop 40
this is the end of the interrupt_handler: loop 40
this is the start of the interrupt_handler: loop 41
this is the end of the interrupt_handler: loop 41
this is the start of the interrupt_handler: loop 42
this is the end of the interrupt_handler: loop 42
this is the start of the interrupt_handler: loop 43
this is the end of the interrupt_handler: loop 43
this is the start of the interrupt_handler: loop 44
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-10 22:06:27 | 显示全部楼层
以上是程序一运行3秒钟左右的结果(前面一大段当然被截去),我没有任何干涉。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表