Boost logo

Boost Users :

Subject: [Boost-users] Some trouble using mutexes
From: Ernest Galbrun (ernest.galbrun_at_[hidden])
Date: 2010-08-20 11:21:30

Dear boost users,

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
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)
(do stuff with the tcp io service)
return 0;

Of course, I also call this function from the main thread.

And I have disruptive behavior, which I don't understand. 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.

Any clue, advice, web link, or soft injures are welcome !

Ernest Galbrun

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at