Re: Will Modern C++ Design ever get fixed?
Witold Kuzminski <witold.kuzminski@gmail.com> writes:
Please see the quote from the article you provided the link to,
and which you co-authored; it is from the introduction:
"This article explains why Singleton isn???t thread safe, how DCLP
attempts to address that problem, why DCLP may fail on both
uni- and multiprocessor architectures, and why you can???t
(portably) do anything about it."
How can one do something about it _non-portably_?
E.g., if the single-time initialization of `shared_field' (only called
when shared_field == NULL) looks like:
{
LockGuard guard (lock);
if (! shared_field)
{
local_variable = make_expensive_data_structure ();
MEMORY_BARRIER ();
shared_field = local_variable;
}
}
where "MEMORY_BARRIER" is __sync_synchronize or equivalent (both acts
as a compiler memory-barrier and emits an appropriate CPU-specific
memory-barrier instruction or whatever).
Then I guess one could encapsulate that in a class that used the
efficient technique on systems where some MEMORY_BARRIER was available
(90% ?), and an explicit lock or something on anything else.
Thanks,
-miles
--
`...the Soviet Union was sliding in to an economic collapse so comprehensive
that in the end its factories produced not goods but bads: finished products
less valuable than the raw materials they were made from.' [The Economist]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]