Boost logo

Boost :

Subject: [boost] [log] how to set attributes under multi-threaded application
From: Jinqiang Zhang (jasonzha_at_[hidden])
Date: 2011-08-03 00:29:24


In boost::log documentation, there's some code as following:

* typedef attrs::mutable_constant< int > int_constant_t;
    boost::shared_ptr< int_constant_t > attr(new int_constant_t(-5));
    lg.add_attribute("MyInteger", attr);
    BOOST_LOG(lg) << "This record has MyInteger == -5";

    **// Change the attribute value
    attr->set_value(100);
    BOOST_LOG(lg) << "This record has MyInteger == 100";
*
Now I have a situation in my multi-threading app:
the 'attr->set_value()' could be called in different threads, so the
following 'BOOST_LOG(lg)...' could access wrong attributes that is set by
another thread. If I use a mutex to protect this, it would be stupid,
because the log line might be filtered out, that means the 'locking mutex'
is not neccessary.

Who can help ?
Jinqiang

*btw, the boost::log documentation isn't too good, when I read it, I felt I
lost in a juggle.*


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk