当前位置: 技术问答>linux和unix
线程创建出错了
来源: 互联网 发布时间:2017-02-17
本文导语: void process(char *buf) { printf("****---> %sn" , buf) ;//出错了 int low = 0 ; int high = strlen(buf) - 1; sleep(1) ; } int main() { FILE *srcfp , *destfp ; static int num = 0 ; ///add up numbers o...
void process(char *buf)
{
printf("****---> %sn" , 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 %sn" , num ,buffer) ;
buffer[strlen(buffer)-1] = '' ;
thread_fd = pthread_create(&threadfd ,NULL, (void *)(&process ), (void*)buffer) ;//这里好像没有穿过去buffer
if(thread_fd == -1 )
{
printf("create pthread failed!n") ;
exit(1) ;
}
}
}
{
printf("****---> %sn" , 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 %sn" , num ,buffer) ;
buffer[strlen(buffer)-1] = '' ;
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("****---> %sn" , (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) ;
{
printf("****---> %sn" , (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);//
改成
thread fd = pthread_create(&htreadfd,NULL,process,(void *)buffer);//
|
void process(char *buf)
---->>>> void process(void *buf)
---->>>> void process(void *buf)