fork子线程之间的通信问题

    Linux下有很多创建子线程的函数,比如fork, vfork, clone,pthread_create,kernel_thread等,当然用的最多的是pthread_create函数。本文章不打算仔细比较这几个函数之间的区别,只讲我在编程过程中遇到的一个小问题:fork创建子线程的通信问题。
    先上代码:
  
  
  
  1. /* funtion:muti-thread commutation test
  2. *date:2016-11-19
  3. *author:HYT
  4. *email:[email protected]
  5. */
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <errno.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <pthread.h>
  12. void *thread_to_process();
  13. void handler(void);
  14. int g_somevar=0;
  15. int main(int argc, char **argv)
  16. {
  17. pthread_t thread;
  18. int thread_fd=0;
  19. memset(&thread, 0, sizeof(thread));
  20. if((thread_fd = pthread_create(&thread, NULL, thread_to_process, NULL)) != 0)
  21. printf("create thread_to_process error!\n");
  22. /*等待线程结束*/
  23. if(thread !=0) { //comment4
  24. pthread_join(thread, NU
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值