leobegin2016 2017-05-21 09:00 采纳率: 100%
浏览 1872
已采纳

linux下 c/c++多线程简单程序编译不过

1 #include
2 #include
3 #include
4 #include
5
6
7 void *thr_fn1(void *arg)
8 {
9 printf("thread 1 returning\n");
10 return((void *)1);
11 }
12
13 void *thr_fn2(void *arg)
14 {
15 printf("thread 2 exiting\n");
16 return((void *)2);
17 }
18
19 int main(void)
20 {
21 pthread_t tid1,tid2;
22 void *tret;
23 pthread_creat(&tid1,NULL,thr_fn1,NULL);
24 pthread_creat(&tid2,NULL,thr_fn2,NULL);
25 pthread_join(tid1,&tret);
26 printf("thread 1 exit code %d\n",(int)tret);
27 pthread_join(tid2,&tret);
28 printf("thread 2 exit code %d\n",(int)tret);
29 exit(0);
30 }

  • 写回答

4条回答 默认 最新

  • oyljerry 2017-05-21 09:01
    关注

    编译的时候要连接lpthread线程库

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿