Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pthread optimize problem

Status
Not open for further replies.

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(&quot;in \n&quot;);
nx=((opcalParam*)param)->nx;
ky = 0;
l = 719;
while ((l < nx) && (tmpParam->in0[l][ky]!=0) && (tmpParam->in1[l][ky]!=0) ) {
val=l++;

}
printf(&quot;out while\n&quot;);
printf(&quot;val=%d\n&quot;, val) ;
sem_post(opcalFinish);
printf(&quot;end \n&quot; );

}
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(&quot;cpcal error\n&quot;);



sem_init(opcalFinish, 0, 0);

sem_post(opcalSema);
sem_wait(opcalFinish);
#endif
printf(&quot;opcal dec i=%d\n&quot;, i);
printf(&quot;out\n&quot;);
printf(&quot;finish\n&quot;);
}

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 -TARG:platform=IP30 -TARG:proc=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 &quot;val = l++&quot;.
it is killing me......
hope someone can help. my working environment is SGI IRIX6.5IP3O.
thanx.
yanchao.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top