Boost logo

Boost Users :

Subject: [Boost-users] [Thread] Strange problem.
From: Germán Diago (germandiago_at_[hidden])
Date: 2011-04-04 09:17:46

Hello. I'm designing a class with a locking policy. I have some code
that does exaclty this:

                if (cond) {
                        out << message.message();
                return *this;

And the lockingpolicy is a class like this one:

struct ThreadSafe {
        boost::mutex io_mutex_;
        boost::unique_lock<boost::mutex> lock_;

        ThreadSafe() : io_mutex_(), lock_(io_mutex_, boost::defer_lock) {}

        void lock() {
                std::cout << "Locking from " << boost::this_thread::get_id() << std::endl;

        void unlock() {
                std::cout << "Unlocking from " << boost::this_thread::get_id() << std::endl;

Then, I create 3 threads and join them in the same order I created them:

boost::thread t1(&doSomething, "Hello1", boost::ref(logsink));
boost::thread t2(&doSomething, "Hello2", boost::ref(logsink));
boost::thread t3(&doSomehting, "Hello3", boost::ref(logsink));


and I get a lock_error. Any help here, please? I can't figure out the problem.

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