免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3617 | 回复: 9
打印 上一主题 下一主题

[应用] pthread_create 挂死问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-03-12 16:02 |只看该作者 |倒序浏览
本帖最后由 hedong0411 于 2013-03-13 09:32 编辑

开发一个模块,使用下载的源码,已经将代码移植成功,功能正常实现(源码没有问题的)。但是最近升级了设备的SDK,编译链也升级了,升级后我的功能不好用了。
代码如下:

static void *WorkerThread( void *arg ) {
           。。。。。。。。。。。。
                    printf("file :%s   function:%s  line:%d        \n",__FILE__,__FUNCTION__,__LINE__);   //运行到这来并打印出来了               
               pthread_mutex_lock( &tp->mutex );
               printf("file :%s   function:%s  line:%d        \n",__FILE__,__FUNCTION__,__LINE__); //这来没有打印出来       
               tp->totalThreads++;
               pthread_cond_broadcast( &tp->start_and_shutdown );
               printf("file :%s   function:%s  line:%d        \n",__FILE__,__FUNCTION__,__LINE__);               
               pthread_mutex_unlock( &tp->mutex );
        。。。。。。。。。
}


  static void *CreateThread( void *arg ) {    //命令行调用该函数

。。。。。。。。。
printf("file :%s   function:%s  line:%d        \n",__FILE__,__FUNCTION__,__LINE__);  //这个打印出来了
        rc = pthread_create( &temp, NULL, WorkerThread, tp );printf("file :%s   function:%s  line:%d        \n",__FILE__,__FUNCTION__,__LINE__);  //这个没有打印出来了,并且命令行挂死了不动,查看ps时发现多了两个线程
。。。。。。。。。。。
}

已经查看过,我的模块已经用新的编译链编译过,且新的lib库libpthread 没有问题(因为我编写过一个pthread_create函数,放到设备中,能够正常执行)。
请各位大侠指点一下,到底是哪里出现问题了。

论坛徽章:
0
2 [报告]
发表于 2013-03-12 19:09 |只看该作者
请大侠们指点

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
3 [报告]
发表于 2013-03-13 09:15 |只看该作者
不lock试试呢

论坛徽章:
0
4 [报告]
发表于 2013-03-13 09:32 |只看该作者
为了简化,我现在把其他的都去掉,只留create代码如下:
static void *WorkerThread( void *arg ) {
        printf("The current pid is :%d\n",pthread_self());    //这里能够打印出来        return NULL;
}

static void *CreateWorker( void *arg ) {
        pthread_t threadt;                               
        printf("test for pthread !\n");      //这里能够打印出来        pthread_create(&threadt, NULL, print_thread_id, NULL);
        sleep(1);  
        printf("this main pid is :%d\n",pthread_self());    //这里打印不出来  似乎是pthread_create没能正确返回,挂死了}

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
5 [报告]
发表于 2013-03-13 11:31 |只看该作者
static void *CreateWorker( void *arg ) {
        pthread_t threadt;                                
        printf("test for pthread !\n");      //这里能够打印出来        
        pthread_create(&threadt, NULL, print_thread_id, NULL);
        printf("after thread create");
        fflush(stdout);
        sleep(1);  
        printf("after sleep 1");
        fflush(stdout);
        int id = pthread_self();
        printf("after get self id\n");
        printf("this main pid is :%d\n", id);    //这里打印不出来  似乎是pthread_create没能正确返回,挂死了}
        fflush(stdout);

这么看一下到哪里

论坛徽章:
0
6 [报告]
发表于 2013-03-13 14:55 |只看该作者
回复 5# T-Bagwell


static void *CreateWorker( void *arg ) {
        pthread_t threadt;                                
        printf("test for pthread !\n");      //这里能够打印出来        
        pthread_create(&threadt, NULL, print_thread_id, NULL);
        printf("after thread create");   //这里就打印不出来了        fflush(stdout);
        sleep(1);  
        printf("after sleep 1");
        fflush(stdout);
        int id = pthread_self();
        printf("after get self id\n");
        printf("this main pid is :%d\n", id);    //这里打印不出来  似乎是pthread_create没能正确返回,挂死了}
        fflush(stdout);




   

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
7 [报告]
发表于 2013-03-13 22:12 |只看该作者
其他的任务还能运行吗?
如果不能的话,就是系统挂了
如果能的话,就有可能是pthread_create阻塞了,那就复杂了

论坛徽章:
0
8 [报告]
发表于 2013-03-14 09:15 |只看该作者
回复 7# T-Bagwell

我在命令行敲击命令调用pthread_create的,然后命令航就挂住了,但是页面、telnet还都可以访问!

排查了两周了,还没搞定,恳请版主帮忙!

   

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
9 [报告]
发表于 2013-03-14 10:52 |只看该作者
回复 8# hedong0411


    不好查了,原因有可能很多了
你这个就是pthread_create阻住了
有可能硬件问题
有可能系统问题
如果是自己封装的pthread_create的话,也可能是pthread_create的问题
还有可能是其他问题,不好说了

论坛徽章:
0
10 [报告]
发表于 2013-03-14 14:25 |只看该作者
应该不是硬件问题和系统问题,因为其他模块调用过该函数。。。。。确实是个比较复杂的问题。。。。
虽然没能解决问题,但还是很感谢版主的热心帮助!多谢多谢多谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP