Re: C++ Threads, what's the status quo?
Jeff Koftinoff wrote:
Here we go again. :)
Le Chaud Lapin wrote:
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.
#include <string>
void f( const std::string &s )
{
std::string my_copy(s);
// do anything or nothing with my_copy here
}
std::string my_label( "testing" );
void thread1()
{
while(1)
{
f( my_label );
}
}
void thread2()
{
while(1)
{
f( my_label );
}
}
Jeff, I do not mean to offend you, but this example is precisely the
reason I made the statements I made before.
my_label is a global variable. The copying operation is an active
operation possibly involving modification of state. There is a _gross_
difference in mentalities going on here.
There are two different points of views coming from two different
groups of programmers:
Group 1 says, "f takes a const & argument, and therefore does not
modify it, so technically, it is const, and therefore it should be
thread safe for read operations"
Group 2 says, "Not only do we think that it is presumptive to imply
that C++ should 'honor' 'read-only' access to global variables, we do
not recognize this point of view."
Note that I could take your example, make a large const global object
with 100 data members, all declared mutable, invoke some operations on
it from two threads and say, "Mon Dieu..!!!" my const global variable
with all those mutable members did not withstand simultaneous access by
multiple threads!!!
No one ever said that a const global object should be "thread safe".
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]