473,386 Members | 1,715 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,386 software developers and data experts.

Is cout << msg an atomic action?



void foo (int n)
{
std::ostringstream oss;
oss << "ABCD: " << n << std::endl;
std::cout << oss.str() << std::flush;
}

That function has been invoked in multiprocessing mode.
Output was something like:
ABCA: B1
C
etc.

Is cout << msg an atomic action?


Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
Feb 4 '08 #1
5 2439

"Alex Vinokur" <al****@users.sourceforge.netwrote in message
news:a8**********************************@1g2000hs l.googlegroups.com...
>

void foo (int n)
{
std::ostringstream oss;
oss << "ABCD: " << n << std::endl;
std::cout << oss.str() << std::flush;
}

That function has been invoked in multiprocessing mode.
Output was something like:
ABCA: B1
C
etc.

Is cout << msg an atomic action?
no:

http://groups.google.com/group/comp....37f881199c5133
(read all...)

Feb 4 '08 #2
On Feb 4, 6:17 am, Alex Vinokur <ale...@users.sourceforge.netwrote:
void foo (int n)
{
std::ostringstream oss;
oss << "ABCD: " << n << std::endl;
std::cout << oss.str() << std::flush;

}
That function has been invoked in multiprocessing mode.
Output was something like:
ABCA: B1
C
etc.
Is cout << msg an atomic action?
It depends on the implementation, but I would not normally
expect to be able to write to the same stream from two different
threads without some external synchronization. Both reading
from and writing to an iostream modify the object itself.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 4 '08 #3
On Feb 4, 11:42*am, James Kanze <james.ka...@gmail.comwrote:
On Feb 4, 6:17 am,AlexVinokur<ale...@users.sourceforge.netwrote:
void foo (int n)
{
* std::ostringstream oss;
* oss << "ABCD: " << n << std::endl;
* std::cout << oss.str() << std::flush;
}
That function has been invoked in multiprocessing mode.
Output was something like:
ABCA: B1
C
etc.
Is cout << msg an atomic action?

It depends on the implementation, but I would not normally
expect to be able to write to the same stream from two different
threads without some external synchronization. *Both reading
from and writing to an iostream modify the object itself.
I realize that
cout << msg1 << msg2;
is not an atomic action.

But is
cout << msg1;
also not atomic one?

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
Feb 4 '08 #4
"Alex Vinokur" <al****@users.sourceforge.netwrote in message
news:38**********************************@q39g2000 hsf.googlegroups.com...
On Feb 4, 11:42 am, James Kanze <james.ka...@gmail.comwrote:
On Feb 4, 6:17 am,AlexVinokur<ale...@users.sourceforge.netwrote:
void foo (int n)
{
std::ostringstream oss;
oss << "ABCD: " << n << std::endl;
std::cout << oss.str() << std::flush;
}
That function has been invoked in multiprocessing mode.
Output was something like:
ABCA: B1
C
etc.
Is cout << msg an atomic action?
It depends on the implementation, but I would not normally
expect to be able to write to the same stream from two different
threads without some external synchronization. Both reading
from and writing to an iostream modify the object itself.
I realize that
cout << msg1 << msg2;
is not an atomic action.
But is
cout << msg1;
also not atomic one?
On a single-threaded application yes; otherwise, well, good luck.

Feb 5 '08 #5
On 4 Feb., 06:17, Alex Vinokur <ale...@users.sourceforge.netwrote:
void foo (int n)
{
* std::ostringstream oss;
* oss << "ABCD: " << n << std::endl;
* std::cout << oss.str() << std::flush;

}

That function has been invoked in multiprocessing mode.

Output was something like:
ABCA: B1
C
etc.

Is cout << msg an atomic action?
I would be most surprised if it was. In theory, an implementation
could make some of these operations atomic, but it would be quite a
stupid thing to do for the simple reason that the atomicity is at the
wrong level.
In case you have user provided operator << these will hardly be atomic
as they can't use the same syncronisation objects as std::cout.

/Peter

/Peter
Feb 5 '08 #6

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

Similar topics

7
by: Ensoul Chee | last post by:
I used #include <iostream.h> int m; cout << "Hexadecimal == 0x" << hex << m << endl; to print value of m in hexadecimal mode. But I got the compile error like this couttest.cpp:20 `hex'...
4
by: karolina | last post by:
Hi I am playing around with visual studio 7.0. Why does the code below do like it does? Where do I set the character set to use in cout, properties->configuration properties->General->character...
4
by: bluekite2000 | last post by:
Here A is an instantiation of class Matrix. This means whenever user writes Matrix<float> A=rand<float>(3,2);//create a float matrix of size 3x2 //and fills it up w/ random value cout<<A; the...
4
by: wangzhihuii | last post by:
Hi all, I'm really confused, can cout<<""; contribute anything to the routine ?!! my programm won't work properly without this trivial sentence. Sincerely vivian
12
by: Filipe Sousa | last post by:
Hi! Could someone explain to me why this operation is not what I was expecting? int main() { int x = 2; std::cout << x << " " << x++ << std::endl; return 0; }
46
by: suresh | last post by:
Hi, For this code snippet, I get the following output, which I am unable to understand. (2^31 = 2147483648) cout<< -2147483648 << endl; cout << numeric_limits<int>::min() <<',' <<...
42
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.