pthread proram will not compile

I am trying to compile a program to trigger false sharing (I have a second program that can detect and fix false sharing). I believe that so far I am correct, but it still refuses to compile. I know that you cannot send a thread function anything, but a sinlge argument, and the way to send more than one argument is by using a struct.

I did use an struct and it still does not compile. I am only trying to fill up two vectors with numbers simultaneously and I am struggling. What am I doing wrong.

The source and out are shown below.

 pgcc example2.c -o exam -lpthread 
PGC-W-0095-Type cast required for this conversion (example2.c: 43)
PGC-S-0037-Syntax error: Recovery attempted by deleting ')' (example2.c: 47)
PGC-W-0095-Type cast required for this conversion (example2.c: 47)
PGC-S-0037-Syntax error: Recovery attempted by deleting ')' (example2.c: 48)
PGC-W-0095-Type cast required for this conversion (example2.c: 48)
PGC/x86-64 Linux 13.6-0: compilation completed with severe errors
[james@james Desktop]$ cat example2.c

#include<pthread.h>

int sum1;
int sum2;

struct arg_struct  {
   int arg1;
   int arg2;
}; 


void *thread1(int v[], int v_count) {
    
     struct arg_struct *args = (struct arg_struct *)args;
     sum1 = 0;
     int i;
     for (i = 0; i < v_count; i++) {
//   printf ( "%d ", i );
     sum1 += v[i];
	}
     return NULL;
}
void *thread2(int v[], int v_count) {

     struct arg_struct *args = (struct arg_struct *)args;
     sum2 = 0; 
     int i;
     for (i = 0; i < v_count; i++) {
//   printf ( "%d ", i );
     sum2 += v[i];
	}
     return NULL;
}


int main ( int argc, char** argv )
{
   pthread_t t1, t2;
   int N = 5000;
   int array1[N];
   struct arg_struct args;
   args.arg1 = array1;
   args.arg2 = N;

   
   pthread_create(&t1,NULL,&thread1,(void *)&args));
   pthread_create(&t2,NULL,&thread2,(void *)&args));
   pthread_join(t1,NULL);

   return 0;
}

.

I am trying to send to thread1 and thread2 and vector and a integer number. For some reson it is not taking it.

Any help appreciated. Thnks in advance.


Respectfully,


THX 1138

Hi THX 1138,

As the error message suggests, you have an extra “)” at the end of the pthread_create functions.

  • Mat