Thread synchronization in stringstream (locale) - what to do?

S

sundman.anders

Hi all!

I have a question about thread synchronization and c++ streams
(iostreams, stringstreams, etc). When optimizing a program for a
multicore processor I found that stringstream was causing a LOT of
synchronization overhead. After a bit of digging I concluded that this
synchronization has to do with the access to a global locale inside
the stream.

The problem can be seen by running the small distilled benchmark code
that compares the threaded performance of stringsream with sprintf:
http://www.optonova.se/asu/main.cpp

From the screen shots of a run with the Intel Thread Profiler one can
clearly see the destructive synchronization behavior (yellow lines) :
http://www.optonova.se/asu/overview.png
http://www.optonova.se/asu/stringstream_zoom.png
http://www.optonova.se/asu/sprintf_zoom.png

In this simple example, stringstream is approximately 2000 times
slower than sprintf!

This was all very interesting, but what I really would like to know is
how to get around the synchronization (I would really like to use
stringstream)?

I'm using the MS Visual Studio 2005 compiler and running the app. on
Windows XP boxes.

Any help will be much appreciated.

Best Regards,
Anders Sundman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top