在我的应用程序中,主函数调用一个函数 - f2,它生成多个线程并且应用程序运行良好。 现在我想在 f2 之前添加一个新函数 f1 以生成一个新线程。这个新线程在屏幕上打印一些东西,然后在 while 循环中进入休眠状态。我得到一次打印,一段时间后应用程序终止。在从 GDB 进行调试时,我收到以下消息:
(gdb) Program received signal SIG34, Real-time event 34.Quit
(gdb) bt
#0 0x0fa97cc8 in __nanosleep_nocancel ()
from /export/home/disk4/omsn/401.03022010/montavista/pro/devkit/ppc/82xx/target/lib/tls/libc.so.6
#1 0x0fa97a50 in __sleep (seconds=0) at sleep.c:137
#2 0x10007098 in f2 (arg=0x204) at main.c:152
#3 0x0fd2197c in start_thread (arg=0x204) at pthread_create.c:256
#4 0x0fac853c in clone ()
at ../sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S:100 warning: Previous frame inner to this frame (corrupt stack?)
代码片段:
main(){
f1(); /*New function added to spawn a new task*/
f2(); /*Existing function spawns several tasks*/
}
谁能告诉我什么是“SIG34 信号,实时事件 34”以及可能导致相同情况的原因。
以下是 f1 功能的详细信息:
int f1(){
pthread_t thread_id;
pthread_attr_t attr;
size_t stack_size;
int ret=0;
pthread_attr_init(&attr);
/*Initialize the stack size*/
pthread_attr_getstacksize (&attr, &stack_size);
printf("Default Stack Size = %d\n", stack_size);
stack_size = 2000;
pthread_attr_setstacksize (&attr, stack_size);
/*Initialize detach state*/
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
printf("Going to spawn thread\n");
ret = pthread_create(&thread_id, &attr, task_func, NULL);
if (ret){
printf("ERROR; return code from pthread_create() is %d\n", ret);
return ret;
}else{
printf("thread successfully spawned, thread id - %d\n", thread_id);
}
pthread_attr_destroy(&attr);
return ret;
}
void* task_func(void* arg){
printf ("Inside %s going for long sleep\n",__FUNCTION__);
sleep(100);
while(1){
printf ("Inside %s\n",__FUNCTION__);
sleep(5);
}
}
最佳答案
要解决这个问题,创建一个.gdbinit
文件,内容如下:
handle SIG34 nostop noprint pass noignore
关于c - 程序在收到信号时终止 - 信号 SIG34,实时事件 34,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6735791/