473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:
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
Feb 12 '08 #1
0 1937

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: klaus hoffmann | last post by:
Is it possible to convert 2 characters from a stringstream to an integer without using an intermediate a 2-bytes string ? The following fragment doesn't work #include <iostream> #include...
4
by: scott | last post by:
hi all, Thx to any one that can offer me help, it will be much appreciated. iv got a multithreaded program and need to use thread synchronization. The synchronization does not have to...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
1
by: FabioAng | last post by:
I implemented a codecvt facet (extracted from TCPL) but while it works well with 'ifstream' it doesn't work at all with 'stringstream'. Am I missing anything ? I tested it with MSVC 7.1 The code...
6
by: Robert Speck | last post by:
Hi there, Can anyone shed anymore light on why "Thread.Suspend()" has been deprecated by MSFT beyond what MSDN says about it. I'm not sure if I quite appreciate the various pitfalls they discuss...
13
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
19
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.