Boost logo

Boost Users :

Subject: Re: [Boost-users] [format] Thread safety of boost::format
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-26 16:44:04


AMDG

James Madison wrote:
> I was browsing the boost::format docs and did not find anything about the
> Thread safety of boost::format. Essentially I want to craft a bunch of
> error handling methods like this:
>
> void ProcessError(...args...)
> {
> static boost::format formatter(...); //Try to save the cost of
> creating this for every single error
>
> //do stuff
>
> LOG(boost::str(formatter % ...args...);
> }
>
> This method would be called from many, many threads. Is this considered
> safe? Is there some general information about the thread safety of
> boost::format methods somewhere in the docs?
>

It is not safe. Look at the declaration of operator%

        template<class T>
        basic_format& operator%(const T& x)

This operation modifies the format object and is therefore
intrinsically not thread-safe.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net