I'm getting a segmentation fault when I try to do
pthread_mutex_lock(&_mutex).
This is really odd, I'm not sure what might have caused it. I have initialized _mutex in the constructor with
pthread_mutex_init(&_mutex,NULL).
anything I can do?
solved it, and I am very annoyed at this. I wanted to send a Producer* as an argument to the function the Pthread runs, so I used &(*iter), where iter is an iterator that runs on a producers vector.
little did I notice it was (rightfully) a vector< Producer* >, which meant I've been sending Producer* * which produced undefined results. grrrrr. Obviously, I didn't notice this because Pthreads is in pure C and therefor uses void* as it's only way of accepting any type of arguments.
Attach a debugger and find out exactly what is causing the segfault. It is possible some pointer is just pointing into randomness or uninitialized area.
Also run valgrind's memcheck and see what that says.
edit
In response to comments below, the usage of the pthread API sound incorrect somewhere. I recommended "PThread Programming" by O'Reilly as a reference. It is what got me going :) I guessed this because the usage of the API is moving a pointer internal to the pthread_mutex_t struct somewhere dangerous. This should not happen with correct usage of the API.
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