compiling a pthread program
am I am trying to compile a program whose code is as shown:
Code:
#include<pthread.h> The output is now shown: Code:
gcc example2.c -o exam -lpthread -lm -lrt -g I am trying to get two threads (thread1 and thread2) to run in parallell and thus create a problem of false sharing. I somehow cannot even get the program to compile. I am sending each separate thread the same arguments. The array, array1, and the value of N. I think that this is the correct format. What am I doing wrong? Any help appreciated. Thanks in advance. Respectfully, jyunker |
Check out some of the examples here Pthread Examples.
You have to pass a void pointer, as the compiler is telling you. I don't think you can pass more than that one argument, you'd have to create a structure and cast it to the void pointer. |
compiling a pthreads program
Okay here is my new code, I created a struct name arg_struct with my two arguments that and I will pass struct
to thread1 and thread2: Code:
and when I run it, I get the following errors: gcc example2.c -o exam -lpthread -lm -lrt -g example2.c: In function ‘main’: example2.c:41: warning: assignment makes integer from pointer without a cast example2.c:45: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type /usr/include/pthread.h:225: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int *, int)’ example2.c:45: error: expected ‘;’ before ‘)’ token example2.c:45: error: expected statement before ‘)’ token example2.c:46: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type /usr/include/pthread.h:225: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int *, int)’ example2.c:46: error: expected ‘;’ before ‘)’ token example2.c:46: error: expected statement before ‘)’ token Now what am I doing wrong? This is my first time programming with pthreads and I am making too many errors. Any help appreciated. Thanks in advance. Respectfully, jyunker |
You have fundamental syntax errors in there which have nothing to do with pthreads, they're just general errors in composing a C program. Read the output of the compiler errors and warnings, go to the lines it is complaining about, and fix your syntax errors.
I suggest you should review the p_greetings.c or p_cpi.c examples in the link previously sent. |
All times are GMT -5. The time now is 09:00 PM. |