Reputation: 75
I've been trying to create a simple thread that reads from stdin and stores input to a linked list. When creating and joining the thread I get the following error:
warning: passing argument 1 of ‘pthread_join’ makes integer from pointer without a cast [-Wint-conversion]
pthread_join(prod_thread, NULL);
I'm passing a thread_t* argument to pthread_join but it seems that it expects an int which confuses me. Can anyone explain why this is happening? Here is the code:
pair_t* head = malloc(sizeof(pair_t));
pthread_t* prod_thread = malloc(sizeof(pthread_t));
pthread_create(prod_thread, NULL, prod_func, head);
pthread_join(prod_thread, NULL);
The prod_func function looks like this:
void* prod_func(void* head) {
...
}
I've also tried calling pthread_join(&prod_thread, NULL);
but then I get the same error.
Upvotes: 0
Views: 317
Reputation: 180998
I'm passing a thread_t* argument to pthread_join but it seems that it expects an int which confuses me.
pthread_join
expects its first argument to be a pthread_t
(not a pthread_t *
). Exactly what type pthread_t
actually is varies from implementation to implementation, but in your implementation it is an integer type. You are passing a pointer instead.
I've also tried calling pthread_join(&prod_thread, NULL); but then I get the same error.
Of course you do. if prod_thread
has type pthread_t *
then its address, &prod_thread
, has type pthread_t **
. That's going the wrong direction (and the result is still a pointer). As you have written your declarations, what you actually want is
pthread_join(*prod_thread, NULL);
Upvotes: 2