AMDG Ernest Galbrun wrote:
I would be really grateful if someone could give me a hint about what I am doing wrong with the mutex and thread class (I am using boost 1.43, on windows XP running visual c++ 2010, the library has been built using the bjam utility).
I have a main thread that creates an object of class robot :
class Robot { private: boost::mutex tcpLock; boost::thread continuousThread; ... }
Robot k3;
this thread launches a thread that makes continuous calls to a member function of the robot. Since this function uses network ressources, I want it to be safe so i use a lock The function called is the only function in my program that uses this lock :
int Robot::sendMsg(string msg, int n, vector<string>* answer) { tcpLock.lock(); (do stuff with the tcp io service) tcpLock.unlock(); return 0; }
Of course, I also call this function from the main thread.
And I have disruptive behavior, which I don't understand.
Do you have multiple Robots? Is the io_service shared between them?
When debugging, I see that the 'active_count' of the tcpLock object stays negative or ==0, which seem absolutely wrong to me, but I don't understand how it could ever be anything other than 0 or 1.
The implementation indicates that the mutex is locked with the high-order bit, which means that a locked mutex will have a negative active count. In Christ, Steven Watanabe