Guest_imported
New member
- Jan 1, 1970
- 0
Hi all:
i have the following code in file ptest.C:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#define XY
typedef struct{
int** in0;
int** in1;
int nx;
}opcalParam;
sem_t *opcalSema, *opcalFinish;
void* opcal(void* param );
void* opcal(void* param ){
int ky, val;
int nx;
int l;
int c=1;
while(c){
opcalParam* tmpParam =(opcalParam*)param;
sem_wait(opcalSema);
printf("in \n"
nx=((opcalParam*)param)->nx;
ky = 0;
l = 719;
while ((l < nx) && (tmpParam->in0[l][ky]!=0) && (tmpParam->in1[l][ky]!=0) ) {
val=l++;
}
printf("out while\n"
printf("val=%d\n", val) ;
sem_post(opcalFinish);
printf("end \n" );
}
return(NULL);
}
int main(void){
int nx = 720;
int ny = 486;
int i, j;
int** in0, **in1;
opcalSema=new sem_t();
opcalFinish=new sem_t();
in0=(int**)calloc(sizeof(int*), nx);
in1=(int**)calloc(sizeof(int*), nx);
for (i=0;i<nx;i++){
in0=(int*)calloc(sizeof(int), ny);
in1=(int*)calloc(sizeof(int), ny);
}
for (i = 0; i < nx; i++) {
for (j=0;j<ny;j++){
in0[j]=1;
in1[j]=1;
}
}
opcalParam theOpcalParam;
theOpcalParam.nx=nx;
theOpcalParam.in0=in0;
theOpcalParam.in1=in1;
//opcal((void*)&theOpcalParam);
#if 1
sem_init(opcalSema, 0, 0);
pthread_t pid;
int pid_err=pthread_create(&pid, NULL, opcal,(void *)(&theOpcalParam));
if (pid_err!=0)
printf("cpcal error\n"
sem_init(opcalFinish, 0, 0);
sem_post(opcalSema);
sem_wait(opcalFinish);
#endif
printf("opcal dec i=%d\n", i);
printf("out\n"
printf("finish\n"
}
when i compiled using debug flag:
CC -I. -I/usr/include/CC -I.. -g -fullwarn -woff 15 -lpthread -lm -lil ptest.C -o out
it works; but when i tried to compile a opt version by the following flag:
CC -I. -I/usr/include/CC -I.. -n32 -O3 -OPT:space=OFF -OPT:unroll_size=30000 -TARGlatform=IP30 -TARGroc=r10000 -mips4 -OPT:Olimit=0 -r10000 -OPT:fast_sqrt=ON -fullwarn -woff 15 -lpthread -lm -lil ptest.C -o out
and run it, it give me a bus error at line "val = l++".
it is killing me......
hope someone can help. my working environment is SGI IRIX6.5IP3O.
thanx.
yanchao.
i have the following code in file ptest.C:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#define XY
typedef struct{
int** in0;
int** in1;
int nx;
}opcalParam;
sem_t *opcalSema, *opcalFinish;
void* opcal(void* param );
void* opcal(void* param ){
int ky, val;
int nx;
int l;
int c=1;
while(c){
opcalParam* tmpParam =(opcalParam*)param;
sem_wait(opcalSema);
printf("in \n"
nx=((opcalParam*)param)->nx;
ky = 0;
l = 719;
while ((l < nx) && (tmpParam->in0[l][ky]!=0) && (tmpParam->in1[l][ky]!=0) ) {
val=l++;
}
printf("out while\n"
printf("val=%d\n", val) ;
sem_post(opcalFinish);
printf("end \n" );
}
return(NULL);
}
int main(void){
int nx = 720;
int ny = 486;
int i, j;
int** in0, **in1;
opcalSema=new sem_t();
opcalFinish=new sem_t();
in0=(int**)calloc(sizeof(int*), nx);
in1=(int**)calloc(sizeof(int*), nx);
for (i=0;i<nx;i++){
in0=(int*)calloc(sizeof(int), ny);
in1=(int*)calloc(sizeof(int), ny);
}
for (i = 0; i < nx; i++) {
for (j=0;j<ny;j++){
in0[j]=1;
in1[j]=1;
}
}
opcalParam theOpcalParam;
theOpcalParam.nx=nx;
theOpcalParam.in0=in0;
theOpcalParam.in1=in1;
//opcal((void*)&theOpcalParam);
#if 1
sem_init(opcalSema, 0, 0);
pthread_t pid;
int pid_err=pthread_create(&pid, NULL, opcal,(void *)(&theOpcalParam));
if (pid_err!=0)
printf("cpcal error\n"
sem_init(opcalFinish, 0, 0);
sem_post(opcalSema);
sem_wait(opcalFinish);
#endif
printf("opcal dec i=%d\n", i);
printf("out\n"
printf("finish\n"
}
when i compiled using debug flag:
CC -I. -I/usr/include/CC -I.. -g -fullwarn -woff 15 -lpthread -lm -lil ptest.C -o out
it works; but when i tried to compile a opt version by the following flag:
CC -I. -I/usr/include/CC -I.. -n32 -O3 -OPT:space=OFF -OPT:unroll_size=30000 -TARGlatform=IP30 -TARGroc=r10000 -mips4 -OPT:Olimit=0 -r10000 -OPT:fast_sqrt=ON -fullwarn -woff 15 -lpthread -lm -lil ptest.C -o out
and run it, it give me a bus error at line "val = l++".
it is killing me......
hope someone can help. my working environment is SGI IRIX6.5IP3O.
thanx.
yanchao.