Re: C++ Threads, what's the status quo?
Le Chaud Lapin wrote:
I showed in response to same problem put forth in a different post that
this is a problem more related to optimization than multi-threading.
IOW, the problem would be present whether the application were
multi-threaded or single-threaded. Yes, it affects multi-threading,
but there are many "anomalies" in C++ that affect many things. An
orthogonal approach to ameliorating the language might be better.
There are strata of problem domains that must be understood to
facilitate multi-threaded programming in C++. I do not think this
particular one should be grouped with the others.
The problem is not optimization; the problem is the C++ specification
does not prohibit the standards conformant compiler to optimize your
multithreaded code into oblivion.
I posted the following example code in this very forum 8 years ago:
This code uses a standards conforming c++ library and if you run
thread1() and thread2() in different threads you will get crashes
and/or memory leaks. More recent compilers have thread-safe
std::string, but nowhere in the c++ standard is there any guarantee
that std::string C.O.W. reference counting is guaranteed to be thread
safe. You are free to say "On compiler version 4.1.x on platform
aaa-bbb-ccc with the options pthread-stdc++ this code is thread safe"
but you cannot say that this code is "thread safe c++ code"
void f( const std::string &s )
// do anything or nothing with my_copy here
std::string my_label( "testing" );
f( my_label );
f( my_label );
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]