在HP UINX上多线程编程问题求教

在HP-unix上,有大文件40G需要读其内容并做相应处理。为提高其处理效率,更好利用多个CPU,特设计如下:
启动CPU数量的线程,每个线程互斥读文件一行fgets,交给处理函数处理(耗费CPU操作),处理结束,读下一行,...,...一直到文件结束...
但使用cc -D_REENTRAN -O2 -lpthread thread4.c -o thread4.exe 编译成功后,执行时候报“Memory fault(coredump)”,不知到为何呢?,此程序执行需要指定环境变量:AUTO_DATA_FILE,请指定为输入文件。
附程序简化代码
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#define MAXTHRDS 2
#define ROWSIZE 64000
pthread_t callThd[MAXTHRDS];
pthread_mutex_t mutexinmod;
long gRows;/*行id*/
typedef long Int32;

FILE *hostf;
FILE *hostLog;
FILE *hostErr;

void *thread_read(void *arg) {
char *line;
unsigned char row[ROWSIZE];
unsigned char Outrow[ROWSIZE];

unsigned long amount = 0;
unsigned long len = 0;
int rc=0;
int ret;
while(1)
{

pthread_mutex_lock (&mutexinmod);
if (feof(hostf) && hostf!=NULL) {
printf("FILE_EOF ,thread id is %d\n",(int) arg);
pthread_mutex_unlock (&mutexinmod);
break;
}
if ( ( line= fgets((char *)row, sizeof(row), hostf) ) == NULL )
{

pthread_mutex_unlock (&mutexinmod);
/* printf("FILE_EOF ,thread id is %d\n",(int) arg); */
break;
}

//此处忽略3000行,耗费CPU的处理程序
gRows++;
printf("write pipe rows: %d by thread id: %d\n",gRows,(int) arg);

pthread_mutex_unlock (&mutexinmod);

}

}
int Init()
{

char hostfile[256];

int status,i;
pthread_attr_t attr;
unsigned long amount = 0;

fflush(stdout);
gRows = 0;

printf("INMOD: AUTO_DATA_FILE=%s\n", getenv("AUTO_DATA_FILE"));
strcpy(hostfile, getenv("AUTO_DATA_FILE"));
if ( (hostf = (FILE *)fopen64(hostfile,"r")) == NULL) {

printf("Open hostdata file(%s) failed! \n",hostfile); fflush(stdout);
return 12;
}

/*初始化线程*/
pthread_mutex_init(&mutexinmod, NULL);

/* Create threads to perform the dotproduct */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

for(i=0;i<MAXTHRDS;i++) {
/* Each thread works on a different set of data */
pthread_create( &callThd[i], &attr, thread_read, (void *)i);
}
for(i=0;i<MAXTHRDS;i++) {
pthread_join( callThd[i], NULL);
}

/*printf("init:ThreadRunningCount is:%d\n",ThreadRunningCount); */
printf("Total thread Count is:%d\n",i);
pthread_attr_destroy(&attr);
/* Wait on the other threads */

return 1;
}

int main(void) {

pthread_t mythread;
int i;

i=Init();
/* After joining, print out the results and cleanup */
printf ("Done. Threaded\n");

pthread_mutex_destroy(&mutexinmod);

exit(0);

}

[2980 byte] By [guanhu123-关湖] at [2008-4-11]
# 1
已经产生了core文件,就调试一下这个core文件。基本可以定位出问题的位置。
http://blog.chinaunix.net/u/6593/showart.php?id=150292
fytzzh-我爱summer at 2007-10-22 > top of Msdn China Tech,Linux/Unix社区,程序开发...
# 2
int Init()中的getenv实现的时候用了全局变量,应该改成getenv_r(char *name,char *buf,size_t len)
wuliang416-Rick at 2007-10-22 > top of Msdn China Tech,Linux/Unix社区,程序开发...
# 3
鉴于电信行业的所有程序都是运行在Unix服务器下,熟练掌握Unix已经成为从事电信开发人员的必备技能,qq群:15530146 与Unix共舞 与开发者共同提高,欢迎Unix牛人加入,期待ing
javasqlbug-javasql虫 at 2007-10-22 > top of Msdn China Tech,Linux/Unix社区,程序开发...
# 4
大家一起来讨论一下,linux下java开发是否有前途?

群号:28941757 欢迎大家一起加入。
csl610-流浪者 at 2007-10-22 > top of Msdn China Tech,Linux/Unix社区,程序开发...
# 5
已经产生了core文件,就调试一下这个core文件。基本可以定位出问题的位置。
enjoythelife1229-听雨 at 2007-10-22 > top of Msdn China Tech,Linux/Unix社区,程序开发...
# 6
ding
guanhu123-关湖 at 2007-10-22 > top of Msdn China Tech,Linux/Unix社区,程序开发...