Boost logo

Boost Users :

Subject: Re: [Boost-users] Why is boost::format::operator% not declared const?
From: Steve Lorimer (steve.lorimer_at_[hidden])
Date: 2013-01-15 20:49:41


> void CalledThousandsOfTimesPerSecondFromManyThreads(float f)
> {
> static const boost::format Formatter("%0.3f");
>
> GetStream() << Formatter % f << GetSomeOtherContent();
> }
>
> I'm pretty sure boost::format is not thread safe

If you think about what it's doing, every time you call operator% it's
inserting a formatted item into it's internal state.

Think about what happens if you feed multiple elements via operator% and
then call .str() - you get a std::string back - it has to store everything
you've fed in internally so that you can access the formatted string later
via .str()



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