Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit declaration of function 'pthread_mutex_init' is invalid in C99

I am trying to lock a method with a mutec from this article here it states create a member variable of the class as such

pthread_mutex_t mutex;

Then initialize it as such

 pthread_mutex_init(&mutex, NULL);

Then use it as such

void MyLockingFunction()
{
    pthread_mutex_lock(&mutex);
    // Do work.
    pthread_mutex_unlock(&mutex);
}

I am getting the following warning at step 2 when I initialize it.

Implicit declaration of function 'pthread_mutex_init' is invalid in C99

What does that mean ? Should I ignore it ?

like image 513
MistyD Avatar asked Apr 25 '15 03:04

MistyD


1 Answers

It means you have not included the header file which declares the function, so the compiler doesn't know anything about it at the point that you use it. You're trying to implicitly declare it by using it, which is invalid.

If you check the man page for pthread_mutex_init(), it tells you that you should use the following line to import the declaration:

#include <pthread.h>

If you put that near the top of your source file, the warning will go away.

like image 146
Ken Thomases Avatar answered Nov 14 '22 23:11

Ken Thomases