免费注册 查看新帖 |

Chinaunix

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

about thread [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-12 17:29 |只看该作者 |倒序浏览
#ifdef HAVE_CONFIG_H
#include <config.h>;
#endif

#include <stdio.h>;
#include <stdlib.h>;
#include<pthread.h>;
struct student
   { char name;
     int  num;
    }
void hello(void*arg)
{
  struct student *student2;
   student2=(struct student *)arg;
   (*student2).name;
   pthread_exit(0);
   
}
main()
{ pthread_t tid;
  struct student*student1;
   (*student1).name='h';
    (*student1).num=2;
   pthread_create( &tid,NULL,(void*)&hello,(void*)student1);
   pthread_join(tid,NULL);

}
error:
main.c:30: two or more data types in declaration of `hello'
Idon`t know why,please help me,thank you!

论坛徽章:
0
2 [报告]
发表于 2005-09-12 17:41 |只看该作者

about thread

http://bbs.chinaunix.net/forum/viewtopic.php?t=599954

论坛徽章:
0
3 [报告]
发表于 2005-09-12 17:52 |只看该作者

about thread

struct student
  { char name;
    int  num;
   };
注意,你结构后面少了个分号,还有
pthread_create( &tid,NULL,(void*)&hello,(void*)student1);
似乎pthread_create( &tid,NULL,hello,(void*)student1);就可以了吧

void hello(void*arg) 是不是该定义成 void *hello(void *arg)???

(*student2).name;
是什么意思?

论坛徽章:
0
4 [报告]
发表于 2005-09-12 18:01 |只看该作者

about thread

  1. #include <stdio.h>;
  2. #ifdef HAVE_CONFIG_H
  3. #include <config.h>;
  4. #endif

  5. #include <stdio.h>;
  6. #include <stdlib.h>;
  7. #include<pthread.h>;
  8. struct student
  9.   { char name;
  10.     int  num;
  11.    };
  12. void *hello(void*arg)
  13. {
  14. struct student *student2;
  15.   student2=(struct student *)arg;
  16.   printf( "%c\n", (*student2).name );
  17.   pthread_exit(0);

  18. }
  19. int main()
  20. { pthread_t tid;
  21. struct student student1;
  22.   (student1).name='h';
  23.    (student1).num=2;
  24.   pthread_create( &tid,NULL,hello,(void*)&student1);
  25.   pthread_join(tid,NULL);

  26. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2005-09-12 18:01 |只看该作者

about thread

另外,指针没有分配空间

论坛徽章:
0
6 [报告]
发表于 2005-09-12 18:07 |只看该作者

about thread

  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>;
  3. #endif

  4. #include <stdio.h>;
  5. #include <stdlib.h>;
  6. #include<pthread.h>;
  7. struct student
  8. {
  9.   char name;
  10.   int num;
  11. };
  12. void *hello(void *arg)
  13. {
  14.   struct student *student2;
  15.   student2 = (struct student *) arg;
  16.   student2->;name='b';
  17.   student2->;num=2;
  18.   pthread_exit (0);
  19. }

  20. main ()
  21. {
  22.   pthread_t tid;
  23.   struct student *student1;
  24.   student1=malloc(sizeof(struct student));
  25.   student1->;name = 'a';
  26.   student1->;num = 1;
  27.   pthread_create (&tid, NULL,hello, (void *)student1);
  28.  //省略返回值判断..
  29.   pthread_join (tid, NULL);
  30.    //省略返回值判断...
  31.   printf("%c %d\n",student1->;name,student1->;num);
  32. }
复制代码

论坛徽章:
0
7 [报告]
发表于 2005-09-12 19:36 |只看该作者

about thread

thanks! Everything goes well
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP