![]() |
Problem with locking pthread mutex
I am attempting to wrap calls to the C++ std::queue object with a mutex but I am running into a problem. It seems that every time the mutex is called it is crashing instead of the pthread_mutex_lock call. It seems that the mutex was not initialized but that is not the case. I am including URLs to the Mutex code so that it can be seen quickly.
Mutex.cpp Mutex.hpp Queue.hpp GDB backtrace of thread that is dying Code:
#0 0x002c83a0 in pthread_mutex_lock () from /lib/libpthread.so.0 |
My guess is that because you don't have copy constructors or assignment operators for any of your classes, one instance gets copied with its mutex specs, then it destructs destroying the mutex with it, leaving the newly-copied instance with a bad mutex. If not, maybe do the following:
Code:
RecursiveMutex::RecursiveMutex (void) : mutex(), attrib() {Kevin Barry |
I ended up restructuring my Mutex classes for the better but I came across something in C++ that I never knew before. There was a NULL pointer calling the method that would push something onto this queue. So in essence the language was executing a method to a NULL object. I have a feeling this has something to do with the fact that both of the methods were inlined (the Queue push method and the method of the NULL executor).
I wanted to put my brain on a frying pan after that. Thanks! |
Calling a function from a NULL pointer is generally safe (albeit malformed) if the class has no virtual functions or virtual base classes and the function doesn't access any data members or base classes (i.e. should have been a static function.) Did you check to see if the function called was static? Was it part of template code? It is possible to do this:
Code:
#include <stdio.h>Kevin Barry |
Yeah, that's basically what I did.
Code:
class Object {The mistake I made was not poking around more in the first place. Live and learn. If someone else wrote the code I could complain them, but this is totally on my shoulders. |
| All times are GMT -5. The time now is 05:22 PM. |