pthread_create invalid arguments...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

void * thread1()
{
        while(1){
                printf("Hello!!\n");
        }
}

void * thread2()
{
        while(1){
                printf("How are you?\n");
        }
}

int main()
{
        int status;
        pthread_t tid1,tid2;

        pthread_create(&tid1,NULL,thread1,NULL);
        pthread_create(&tid2,NULL,thread2,NULL);
        pthread_join(tid1,NULL);
        pthread_join(tid2,NULL);
        return 0;
}


It says invalid arguments for pthread_create()?

Why is this? I do have everything set up with -pthread.
1
2
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg);


Is signature of the pthread_create call. Check the signature of you thread functions, parameter list cant be empty it should be void * thread1(void *) not void * thread1()
You got it!
change the function signature to void* thread1(void*)

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

void* thread1(void*)
{
while(1){
printf("Hello!!\n");
}
}

void* thread2(void*)
{
while(1){
printf("How are you?\n");
}
}

int main()
{
int status;
pthread_t tid1,tid2;

pthread_create(&tid1,NULL,thread1 ,NULL);
pthread_create(&tid2,NULL,thread2,NULL);
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
return 0;
}
~
Topic archived. No new replies allowed.