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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sundman.anders@gmail.com

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

    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:


    From the screen shots of a run with the Intel Thread Profiler one can
    clearly see the destructive synchronization behavior (yellow lines) :




    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
Working...