首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

线程创建出错了解决方法

2012-04-21 
线程创建出错了void process(char *buf){printf(****--- %s\n , buf) //出错了int low 0 int high

线程创建出错了
void process(char *buf)
{
  printf("****---> %s\n" , buf) ;//出错了
  int low = 0 ;
  int high = strlen(buf) - 1;
  sleep(1) ;
}

int main()
{
  FILE *srcfp , *destfp ;
  static int num = 0 ; ///add up numbers of rows
  char buffer[MAXSIZ];
  //char *buffer = malloc(MAXSIZ*sizeof(char)) ;

  void process(char* buf) ;

  if((srcfp = fopen("srcfile" , "r")) == NULL)
  {
  printf("open srcfile error!\n") ;
  exit(1) ;
  }

  if((destfp = fopen("destfile" , "w+")) == NULL)
  {
  printf("open or create destfile error!\n") ;
  exit(1) ;
  }


  while((fgets(buffer , MAXSIZ , srcfp)) != NULL)
  {
  pthread_t threadfd , thread_fd;
  num++ ;
  printf("%d %s\n" , num ,buffer) ;
  buffer[strlen(buffer)-1] = '\0' ;
  thread_fd = pthread_create(&threadfd ,NULL, (void *)(&process ), (void*)buffer) ;//这里好像没有穿过去buffer
  if(thread_fd == -1 )
  {
  printf("create pthread failed!\n") ;
  exit(1) ;
  }
  }
}

[解决办法]
void* process(void *buf)
{
printf("****---> %s\n" , (char *)buf) ;//出错了
int low = 0 ;
int high = strlen(buf) - 1;
sleep(1) ;
}

main函数中:void process(char* buf) ;--这个函数声明去掉

thread_fd = pthread_create(&threadfd ,NULL, process , (void*)buffer) ;
[解决办法]
thread_fd = pthread_create(&threadfd ,NULL, (void *)(&process ), (void*)buffer) ;//这里好像没有穿过

改成
thread fd = pthread_create(&htreadfd,NULL,process,(void *)buffer);//
[解决办法]
void process(char *buf)
---->>>> void process(void *buf)

热点排行