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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With