QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1668|回复: 3

pthread问题

[复制链接]
发表于 2005-11-28 02:21:03 | 显示全部楼层 |阅读模式
#include<pthread.h>
#include<stdio.h>

int sum;
void *runner(void *param);

int main(int argc, char *argv[])
{
  pthread_tid;
  pthread_attr_t attr;

  if(argc!=2){
    fprintf(stderr,"usage:a.out<integer value\n>");
    return -1;
  }
  if(atoi(argv[1])<0){
    fprintf(atderr,"%d must be>=0\n",atoi(argv[1]));
    return -1;
  }
  pthread_attr_init(&attr);
  pthread_create(&tid,&attr,runner,argv[1]);
  pthread_join(tid,NULL);
  printf("sum = %d\n",sum);
}

void *runner(void*param)
{
  int i,upper = atoi(param);
  sum = 0 ;
  for(i =1;i<=upper;i++)
    sum+=i;
  pthread_exit(0);
}







  pthread_attr_init(&attr);
  pthread_create(&tid,&attr,runner,argv[1]);
  pthread_join(tid,NULL);


以上三个函数个别是做些什么用的?? & 形参个别代表什么??

这种的代码哪种书上才有可以推荐吗??

谢谢
发表于 2005-11-28 08:56:55 | 显示全部楼层
man 文档关于 pthread 的内容非常全面
回复

使用道具 举报

 楼主| 发表于 2005-11-28 16:25:10 | 显示全部楼层
请问有没中文 man??哪边可以下载?

谢谢
回复

使用道具 举报

发表于 2005-12-7 06:48:50 | 显示全部楼层
简单地说,pthread_init()是初使,pthread_create()是创建,最后一个是等待结束。

有很多讲Linux下的C语言编程的东西都会详细地讲pthread的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-6-4 05:05 , Processed in 0.116026 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表