LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   so confusing (https://www.linuxquestions.org/questions/programming-9/so-confusing-108244/)

c12ayon 10-25-2003 12:54 AM

so confusing
 
#include<stdio.h>
#include<pthread.h>

void printMsg(void);

int main(){
pthread_t accnt1, accnt2;
pthread_create(accnt1, NULL, printMsg(), );
return 0;
}
void printMsg(){
printf("Hello PThread\n");
}

it shows:
tes.c: In function `main':
tes.c:8: error: syntax error before ')' token

is it the rite way to use pthread_create?

Looking_Lost 10-25-2003 01:42 AM

Don't know much about it but that comma doesn't look right


pthread_create(accnt1, NULL, printMsg(), );

Mara 10-26-2003 03:11 PM

That's how pthread_create call should look like:
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg);

So, in your case, it should be:
pthread_create(accnt1, NULL, printMsg(),NULL );

BTW It's a good idea to check if pthread_create ends with a success.

infamous41md 10-26-2003 03:14 PM

you dont put the brackets printMsg(), it should be:
pthread_create(accnt1, NULL, printMsg, NULL); and optionally to make gcc stfu
pthread_create(accnt1, NULL, (void *)printMsg, NULL);

Mara 10-26-2003 03:18 PM

You're right infamous41md, I was copying. :)

c12ayon 10-26-2003 11:52 PM

thx guys...


All times are GMT -5. The time now is 07:49 AM.