免费注册 查看新帖 |

Chinaunix

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

请教高手关于消息队列和线程编程的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-05-14 15:01 |只看该作者 |倒序浏览
我在freebsd5.21下写了一个多线程的程序,使用了两个消息队列,源码摘录如下:
main()
{  ...........................
      
       if((n=pthread_create(&tid1, NULL, &dofunc1, NULL))==0{
                fprintf(stderr,"thread1:[ID=%d] starting...\n",*tid);
                return;
        }

       if((n=pthread_create(&tid2, NULL, &dofunc2, NULL))==0{
                fprintf(stderr,"thread2:[ID=%d] starting...\n",*tid);
                return;
        }


    ........................
        pthread_join(tid1, NULL);
        pthread_join(tid2, NULL);
    .................
   exit(0);
}

void *
dofunc1(void *vptr)
{
      fprintf(stderr,"thread1:ID=[%d] begin......\n",pthread_self());
     rel = msgrcv(msgid1, ( MSGCMPP * ) rcvpkt1, CMPP_MAX_LEN, 0, MSG_NOERROR);
      .............
}

void *
dofunc2(void *vptr)
{
      fprintf(stderr,"thread2:ID=[%d] begin......\n",pthread_self());
     rel = msgrcv(msgid2, ( MSGCMPP * ) rcvpkt2, CMPP_MAX_LEN, 0,   MSG_NOERROR);
      .............
}

编译通过,执行结果居然如下
Pthread1:ID=[134754304] starting......
Pthread2:ID=[134754321] starting......
Pthread1:ID134754304] begin......


没有出现Pthread2:ID134754321] begin......这一信息,好象是线程1阻塞在msgrcv时,线程2没有执行,结果是无法实现并行运行,这是为什么???

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2004-05-14 15:18 |只看该作者

请教高手关于消息队列和线程编程的问题

发到c版去,或者csdn.他们比较专业一点.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP